Get alerts from SharePoint 2010 site using web service


Get alerts from SharePoint 2010 site using web service

In this article you will see how to get all the alerts from a SharePoint 2010 web site using a web service. In this you will see how to get all the alerts for the particular user from the SharePoint 2010 web site using a web service. Navigate to the SharePoint site. Go to Site Actions, and then click on Site Settings.

1.gif

In the Site Administration section, click on User Alerts.

2.gif

Select the user from the drop down and then click on Update button. You could be able to view all the alerts for the selected user.

3.gif

Get Alerts using web service:
 
Steps Involved:

  1. Open Visual Studio 2010 by going Start | All Programs | Microsoft Visual Studio 2010 | Right click on Microsoft Visual Studio 2010 and click on Run as administrator.

  2. Go to File tab, click on New and then click on Project.

  3. In the New Project dialog box, expand the Visual C# node, and then select the Windows node.

  4. In the Templates pane, select Console Application.

  5. Enter the Name as WebServices and then click OK.

  6. In the solution explorer, right click on the solution and then click on Properties.

  7. Select the Application tab, check whether ".Net Framework 3.5" is selected for Target Framework.

  8. Select the Build tab, check whether "Any CPU" is selected for Platform Target.

  9. Right click on References folder and then click on "Add Service Reference".

  10. In the "Add Service Reference" wizard click on "Advanced..." button.

  11. In the "Service Reference Settings" wizard click on "Add Web Reference...".

  12. In the URL section, enter the alerts web service url (http://serverName10:10736/sites/ECT2/_vti_bin/alerts.asmx) and then click on enter.

  13. Enter the Web Reference Name as AlertsWebServiceReference then click on "Add Reference" button.

  14. ck on Ok.

  15. Web Reference will be added successfully.

  16. Double click on Program.cs and add the following Namespace.   
    1.     using WebServices.AlertsWebServiceReference;

  17. Replace Program.cs with the following code snippet.

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Web;

using WebServices.AlertsWebServiceReference;

 

namespace WebServices

{

    class Program

    {

        static void Main(string[] args)

        {

            Alerts alerts = new Alerts();

            alerts.Url = "http://serverName10:10736/sites/ECT2/_vti_bin/alerts.asmx";

            alerts.Credentials = CredentialCache.DefaultCredentials;

            AlertInfo alertInfo = alerts.GetAlerts();

            Console.WriteLine("AlertWebTitle: "+alertInfo.AlertWebTitle);

            Console.WriteLine("AlertServerName: "+alertInfo.AlertServerName);

            Console.WriteLine("AlertServerType: " + alertInfo.AlertServerType);

            Console.WriteLine("AlertServerUrl: "+alertInfo.AlertServerUrl);

            Console.WriteLine("Alerts Number:" + alertInfo.Alerts.Length.ToString());

            Console.WriteLine("CurrentUser: "+alertInfo.CurrentUser);

            foreach (Alert alert in alertInfo.Alerts)

            {

                Console.WriteLine("Alert Information: ");

                Console.WriteLine("-------------------");

                Console.WriteLine("Title: "+alert.Title);

                Console.WriteLine("AlertForUrl: "+alert.AlertForUrl);

            }

            Console.ReadLine();

 

        }

    }

}

 

Output


4.gif

 

Summary:

 

Thus in this article you have seen how to get all the alerts for a particular user from SharePoint web site using web service.