.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
 
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Top 5 Contributors of the Month
david stephan

Home >> Code Snippets >> SharePoint >> Post New Resource Bookmark and Share   

 Subscribe to Code Snippets

Get All Alerts in site collection

Posted By:Sagar Pardeshi       Posted Date: November 30, 2013    Points: 40    Category: SharePoint    URL: http://www.dotnetspark.com  

Get all alerts in site collection
 

SPsite rootsite=SPContext.Current.Site; 
        SPWeb rootweb=rootsite.OpenWeb();
        SPSecurity.RunWithElevatedPrivileges(delegate() 
        { 
        SPList alertList=rootweb.Lists["myList"];
        Using(SPSite sitecollection=new SPsite(rootsite.ID))
        { 
            foreach(SPWeb curretweb in sitecollection.AllWebs)
            { 
                Using(SPWeb oweb=sitecollection.OpenWeb(curretweb.ID))
                { oweb.AllowUnsafeUpdates=true;
                    try 
                    { 
                        SPAlertCollection allalerts=oweb.Alerts; 
                        Foreach(SPAlert alertitem in allalerts)
                        { 
                            AddAlertToTable(alertList,alertitem);
                        }
                    } 
                    Catch(Exception ex)
                    {
                        Console.writeline("Delete fail:"+ex.Message);
                    } 
                    
                    Oweb.AllowUnsafeUpdate=false;
                } 
            } 
        } 
    }); 
}


     

Further Readings:

Responses

No response found. Be the first to respond this post

Post Comment

You must Sign In To post reply
Find More code samples in C#, ASP.Net, Vb.Net and more Here

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend