无法从 C# 中的工作流任务更新列表项
我没有收到任何异常,但下面的代码根本不起作用。有什么想法吗?
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);
}
}
)};
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);
}
}
)};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
看起来您没有通过字段的内部名称引用该字段,这就是您在使用
SPListItem
的索引器访问字段时必须引用字段的方式。尝试类似的方法,应该可以工作。请注意,内部名称从不包含空格,而是被其十六进制字符串替换,如上所示。
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 likeand it should work. Note that Internal names never contain spaces and are replaced by their hex character string like above.