0
votes

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?

2

2 Answers

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

Get more details Here

0
votes

The SharePoint linq provides doesn't work with ElevatedPrivileges. It accesses the SPWeb.Current instance which will have the access rights of the request and not the elevated user.

http://jcapka.blogspot.com/2010/05/making-linq-to-sharepoint-work-for.html

There's a work around, which I've implemented generally the same thing. It's a big awkward but it works as far as I can tell.