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.
精彩评论