开发者

Unable to update a list item from a workflow task in C#

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

SPSecurity.RunWithElevatedPrivileges(dele开发者_如何学运维gate() {            
        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);
         }
   }
)};


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜