更新Sharepoint任务的扩展属性或批准注释

问题描述 投票:0回答:1

我正在尝试使用CSOM以编程方式更新SharePoint任务。我能够成功批准任务,但不确定如何更新评论。

可以使用ExtendedProperties作为HashTable来检索注释,但是我无法为其设置值。如何更新批准注释?

下面是批准任务的代码:

                using (ClientContext ctx = new ClientContext("http://abc/sites/TLS/low"))
            {
                Web web = ctx.Web;
                List oList = web.Lists.GetByTitle("Tasks");
                ListItem listitem = oList.GetItemById(784);
                ctx.Load(listitem);
                ctx.ExecuteQuery();
                Hashtable ht = GetExtendedPropertiesAsHashtable(listitem);
                listitem["Completed"] = true;
                listitem["PercentComplete"] = 1;
                listitem["Status"] = "Approved";
                listitem["WorkflowOutcome"] = "Approved";
                listitem["FormData"] = "Completed";
                //listitem["__ModerationComments"] = "Sdfs";
                //listitem["ows_FieldName_Comments"] = "Sdfs";
                //ht["ows_FieldName_Comments"] = "sdsds";
                listitem.Update();
                ctx.ExecuteQuery();
            }

下面是获取任务项的ExtendedProperties的代码:

        public static Hashtable GetExtendedPropertiesAsHashtable(ListItem task)
    {
        if (task == null)
        {
            throw new ArgumentNullException();
        }
        Hashtable properties = new Hashtable();
        string extProperties = (string)task["ExtendedProperties"];
        if (!string.IsNullOrEmpty(extProperties))
        {
            var reader = new XmlTextReader(new StringReader("<Root " + extProperties + " />"))
            {
                WhitespaceHandling = WhitespaceHandling.Significant
            };
            reader.MoveToContent();
            if (!reader.HasAttributes)
            {
                return properties;
            }
            while (reader.MoveToNextAttribute())
            {
                string propName = reader.Name.Substring(4);
                properties[propName] = reader.Value;
            }
        }
        return properties;
    }
sharepoint-2013 csom sharepoint-workflow extended-properties
1个回答
0
投票

您可以尝试通过此方法来更新批准注释:

listitem["ExtendedProperties"] = "ows_FieldName_Comments='comment' ";
© www.soinside.com 2019 - 2024. All rights reserved.