Chanaka

Update field values of Infopath form library Programatically

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");

}

 

NB:-

(1) We Cant use this method under "SPSecurity.RunWithElevatedPrivileges(delegate.."

(2) If we want to edit a field that is filling from infopath form we have to use

oListItem["Fld_x0020_Other_x0020_Names"]   instead of oListItem["ProgramaticField"]