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.
In the Site Administration section, click on
User Alerts.
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.
Get Alerts using web service:
Steps Involved:
-
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.
-
Go to File tab, click on New
and then click on Project.
-
In the New Project dialog box,
expand the Visual C# node, and then select the Windows node.
-
In the Templates pane, select
Console Application.
-
Enter the Name as WebServices
and then click OK.
-
In the solution explorer,
right click on the solution and then click on Properties.
-
Select the Application tab,
check whether ".Net Framework 3.5" is selected for Target Framework.
-
Select the Build tab, check
whether "Any CPU" is selected for Platform Target.
-
Right click on References
folder and then click on "Add Service Reference".
-
In the "Add Service Reference"
wizard click on "Advanced..." button.
-
In the "Service Reference
Settings" wizard click on "Add Web Reference...".
-
In the URL section, enter the
alerts web service url (http://serverName10:10736/sites/ECT2/_vti_bin/alerts.asmx)
and then click on enter.
-
Enter the Web Reference Name
as AlertsWebServiceReference then click on "Add Reference" button.
-
ck on Ok.
-
Web Reference will be added
successfully.
-
Double click on Program.cs and
add the following Namespace.
1. using WebServices.AlertsWebServiceReference;
-
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
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.