Archive

Archive for July, 2007

RunWithElevatedPrivileges tricks

July 12th, 2007 No comments

SPSecurity exposes a method called “RunWithElevatedPrivileges” which gives you an option to elevate the privilege to the application pool identity under which your code is executing. Looks nice, eh?


But Wait a second!! You are not done yet. I wish it was that easy when it comes to impersonation. In order to get this method call to properly impersonate your application pool identity you need to do some more work. Basically, SPSite and SPWeb objects created outside do not have Full Control even when referenced inside the delegate (anonymous method), so you need to find out their GUID before impersonation is performed and re-create the context one more time. Finally,never forget to dispose your objects!


 


//Don’t dispose the following two objects. Sharepoint will take care of their disposal when page is completely rendered.
SPWeb  webInUserContext = SPContext.Current.Web;
SPSite SiteInUserContext = SPContext.Current.Site;
               
Guid webGuid = webInUserContext.ID;
Guid siteGuid = SiteInUserContext.ID;


SPSecurity.RunWithElevatedPrivileges(delegate()
                {
                    // get the site in impersonated context
                    using (SPSite site = new SPSite(siteGuid))
                    {


                        // get the web in the impersonated context
                        SPWeb web = site.OpenWeb(webGuid);
                   
                       // Do your work here  
                       


                     web.Dispose();
                    }


               });



Categories: Uncategorized Tags:

Thanks Microsoft!

July 3rd, 2007 No comments

Earlier today I was informed by Microsoft that I have been awarded an MVP (Most Valuable Professional) in Microsoft Office SharePoint Server 2007. I just wanted to post a great “thanks” to those people who nominated and voted for me especially my former colleague, Eli Ribbilard and my new MVP lead Sasha Krsmanovic. I’d also like to extend my sentiments to my blog readers who read my blog and email me with questions and enlighten me with their warm comments. They truly make me feel to be part of our SharePoint community and keep me well-motivated to contribute as much as possible.


I feel much honored to have received this award and truly enjoy being deeply involved in our community. Thanks Microsoft and everyone!



Categories: Uncategorized Tags: