0

I am not getting any exceptions, but the code below is simply not working. Any ideas?

SPSecurity.RunWithElevatedPrivileges(delegate() {            
        using (SPWeb web = this.workflowProperties.Web) {
        try {
          SPListItem item = web.Lists["NewHireFormsLibrary"].Items[workflowProperties.ItemId - 1];
          item["Field 1"] = "Gotcha!!!";
          item.Update();

          LogHistory("Information", "Workflow indexing complete.  " + item["Field 1"], "");
         }
         catch (Exception ex) {
             LogHistory("Error", ex.Message, ex.StackTrace);
         }
   }
)};
James Curran
  • 101,701
  • 37
  • 181
  • 258
billsecond
  • 612
  • 3
  • 21
  • 50
  • Okay, just an update. This works if I apply the item to a non-infopath field. How can i update an infopath field? – billsecond Jul 29 '10 at 05:18

1 Answers1

2

It looks like you are not referencing the field by it's Internal Name, which is how you have to reference fields when accessing them with the SPListItem's indexer. Try something like

item["Field_x0020_1"] = "Gotcha!!!";

and it should work. Note that Internal names never contain spaces and are replaced by their hex character string like above.

Steve Danner
  • 21,818
  • 7
  • 41
  • 51
  • Im going to try it, but how do I figure out what the internal name is? – billsecond Jul 29 '10 at 05:07
  • It didn't work, actually. Does it matter that it is a infopath form document library? – billsecond Jul 29 '10 at 05:15
  • I normally just write a quick app to loop through all the fields for a given list item and print out SPField.InternalName. Optionally, you could get each fields ID (Guid) and use that instead of the internal name. Your infopath fields might have some kind of prefix or something prepended to the internal name (though I'm not very familiar with infopath integration, so I can't say for sure). – Steve Danner Jul 29 '10 at 12:53
  • 1
    SharePoint Manager (http://spm.codeplex.com/) reveals the internal field names and much more. – Jason Weber Jul 29 '10 at 16:53