When you try to update or delete an List/Documentlibrary item you may get the
following error
“The security validation for this page is invalid. Click
Back in your Web browser, refresh the page, and try your operation again”
This one was driving me nuts for a while as the error description is not very helpful (as usual). 
This is because the "user" doesn't have enough permissions.
One way to handle this is to temporarily allow unsafe update on the web before updating/deleting the List/Documentlibrary item (if you can't grant additional permissions to the "user")
One way to handle this is to temporarily allow unsafe update on the web before updating/deleting the List/Documentlibrary item (if you can't grant additional permissions to the "user")
See code below
web.AllowUnsafeUpdates = true;
item.Delete();
web.AllowUnsafeUpdates = false;
Note : If this helped you, please add a comment and share the link as it will motivate me to post more solutions like this.
No comments:
Post a Comment