My SharePoint Blog

Blogs On SharePoint Technologies


Search Site

Recent posts

Recent comments

Tags

Don't show

    Categories


    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2008

    SharePoint Elevated Security

    In order for a user to perform tasks on a SharePoint site that require higher permissions than they have, you can use "RunWithElevateedPrivileges" method of the SPSecurity object. The account used is assumed to be the "system account".

    SPSecurity.RunWithElevatedPrivileges(delegate()
    {
        // CODE TO RUN WITH ELEVATED PRIVILEGES GOES HERE //
        SPSite siteCollection = new SPSite("https://foobar.com");
        SPWeb mySite = siteCollection.AllWebs["tpms/review"];
        mySite.AllowUnsafeUpdates = true;
        SPWeb rootSite = siteCollection.OpenWeb("/");
        SPListItemCollection myList = mySite.Lists["Performance Improvement Notice Tasking"].Items;
        SPListItem updateItem = myList.GetItemById((int)globalIdNumber);
        updateItem["Title"] = "Foobar";
        updateItem.Update();
        mySite.Dispose();
        rootSite.Dispose();
        // END ELEVATED CODE BLOCK //
    });

    This mean no more .credentials auth crap.


    Categories: SharePoint
    Posted by Kevin on Thursday, September 27, 2007 2:09 PM
    Permalink | Comments (0) | Post RSSRSS comment feed