Problem: An error occurred while updating splistitem, that is, item. Update (), after elevation of permission.

Source: Internet
Author: User

 

[Problem description]

When updating list items in the list, we often need to useSpsecurity. Runwithelevatedprivileges (Delegate(){}ToItem. Update ()But sometimes this will cause errors.

 

Solution 1]

1.SetItem. Update ()After the permission is upgradedSiteAnd text in the elevation of permissions:

SplistList =Null;

Spsecurity. Runwithelevatedprivileges (Delegate()

{

Site =New Spsite(Sitecollectionurl );

Web = site. rootweb;

});

 

List = web. Lists ["Notification library"];

SplistitemItem = List. Items. Add ();

IItem [title] ="123 ";

Item. Update ();

 

2.After the permission is upgradedListitemSimilar errors may also occur and can be solved in the same way:

Protected VoidPage_load (ObjectSender,EventargsE)

{

 

Spsecurity. Runwithelevatedprivileges (Delegate()

{

Updateitem ();

}

);

}

 

VoidUpdateitem ()

{

SpsiteSite =New Spsite("Http: // ssjin073: 9032");

 

SpwebWeb = site. rootweb;

 

//Force set context object

Httpcontext. Current. items ["Httphandlerspweb"] = Web;

 

Web. allowunsafeupdates =True;

SplistList = web. Lists ["Mainlist"];

 

SplistitemItem = List. items [0];

 

Item ["Title"] =Datetime. Now. tostring ();

 

Item. Update ();

 

Web. Dispose ();

Site. Dispose ();

}

 
The second method comes from:Http://www.cnblogs.com/jianyi0115/archive/2008/04/11/1148827.html

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.