Search code examples
c#visual-studiosharepointweb-parts

Sharepoint access to list ignore user permission


I created web part (something like wizard) and need change item value in list, but when get list item, they haven't items (logged user haven't access to this list). Can I ignore sharepoint permission, and update this value?

I use LINQ to sharepoint and get context:

using (SystemOcenContextDataContext ctx = new SystemOcenContextDataContext("http://sh2010/sites/270"))
{
    // code :)
}

Update:

make test when get list using:

  SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                using (SPSite ElevatedSite = new SPSite("http://sh2010/sites/270"))
                {
                    using (SPWeb ElevatedWeb = ElevatedSite.OpenWeb())
                    {
                        list = ElevatedWeb.Lists["Ankiety i oceny"];
                    }
                }
            });

the object list "have" items

but in my project I use sharepoint linq datacontext when using:

 SPSecurity.RunWithElevatedPrivileges(delegate()
            {

            using (SystemOcenContextDataContext ctx = new SystemOcenContextDataContext("http://sh2010/sites/270"))
            {
                item = ctx.AnkietyIOceny.First();
            }

        });

the context(ctx) didn't have any items :/

any idea?


Solution

  •   SPSecurity.RunWithElevatedPrivileges(delegate()
      {
            // Pur your code here.
      }); 
    

    Get more details Here