views:

38

answers:

1

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);
         }
   }
)};
+1  A: 

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
Im going to try it, but how do I figure out what the internal name is?
Bill Daugherty
It didn't work, actually. Does it matter that it is a infopath form document library?
Bill Daugherty
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
SharePoint Manager (http://spm.codeplex.com/) reveals the internal field names and much more.
Jason Weber