(1) We should allow unsafe upates = true
(2) We should check out the file
(3) We cant use our item update event inside "SPSecurity.RunWithElevatedPrivileges(delegate.."
Code is simple
SPSite objSite = new SPSite("http://sharepointsvr:123/");
SPWeb objWeb = objSite.RootWeb;
SPFolder oFolder = objWeb.GetFolder("Participant");
SPFileCollection collFiles = oFolder.Files;
objWeb.AllowUnsafeUpdates = true;
foreach (SPFile oFile in collFiles.Folder.Files)
{
SPListItem oListItem = oFile.Item;
oListItem.File.CheckOut();
oListItem["ProgramaticField"] = "Chanaka has done it";
oListItem.SystemUpdate();
oListItem.File.CheckIn("chana did");
}
No comments:
Post a Comment