无法从 C# 中的工作流任务更新列表项

发布于 2024-09-12 04:13:52 字数 579 浏览 3 评论 0原文

我没有收到任何异常,但下面的代码根本不起作用。有什么想法吗?

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

森林散布 2024-09-19 04:13:52

看起来您没有通过字段的内部名称引用该字段,这就是您在使用 SPListItem 的索引器访问字段时必须引用字段的方式。尝试类似的方法

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

应该可以工作。请注意,内部名称从不包含空格,而是被其十六进制字符串替换,如上所示。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文