About Me

My photo
a Dynamic and Energetic guy.....

Tuesday, July 28, 2009

Change the data in a Infopath form library programatically

First we have to take care few things
(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["ProgramaticField"] = "Chanaka has done it";
oListItem.File.CheckIn("chana did");

No comments:

My Masters