Quantcast
Channel: shopSharepoint.com: Blog
Viewing all articles
Browse latest Browse all 80

Sharepoint 2010 : Things to remember while using RunWithElevatedPrivileges

$
0
0

1. you should initiate a SPSite object with in the SPSecurity.RunWithElevetedPrivilges. 

2. Create SPSite using ID. This is very important thing. 

3. Make sure to add web.AllowUnsafeUpdates = true  before your logic and add web.AllowUnsafeUpdates = false after your logic

See the below sample - 

             SPSecurity.RunWithElevatedPrivileges(delegate()
               {
               SPWeb webContxt = SPContext.Current.Web;
           Guid newSite;

               using (SPSite site = new SPSite(webContxt.Site.ID))
               {
                   using (SPWeb web = site.OpenWeb(webContxt.ID))
                   {
                       web.AllowUnsafeUpdates = true;
                        //Add your code

                      web.AllowUnsafeUpdates = false;
                   }
               }
           });


Viewing all articles
Browse latest Browse all 80

Trending Articles