[英]Adding a sub-task to a task in sharepoint online with c# (using Microsoft.SharePoint.Client)
I have managed to add tasks in Sharepoint online with c#, where I am struggling (maybe for the lack of the better search terms is the following): 我已经设法使用c#在Sharepoint在线添加任务,而我在其中奋斗(也许是由于缺少更好的搜索词):
How do I add a sub-task to an existing task/ assign a child task to a parent? 如何将子任务添加到现有任务/如何将子任务分配给父任务?
The answer seems to lay within the ParentID field, which shows a connection to another task, when entered manually online through the Sharepoint task list. 答案似乎在ParentID字段中,该字段显示通过Sharepoint任务列表手动在线输入时与另一个任务的连接。
the field, in that case, shows for the child node the following entry: 在这种情况下,该字段为子节点显示以下条目:
- [12] {[ParentID, Microsoft.SharePoint.Client.FieldLookupValue]} System.Collections.Generic.KeyValuePair<string, object>
Key "ParentID" string
- Value {Microsoft.SharePoint.Client.FieldLookupValue} object {Microsoft.SharePoint.Client.FieldLookupValue}
LookupId 60 int
LookupValue "60" string
TypeId "{f1d34cc0-9b50-4a78-be78-d5facfcccfb7}" string
I have the ID (eg 60) for the parent node to be and I understand the TypeID to be fix from research on the internet (hope my research on this is correct). 我有父节点的ID(例如60),并且我理解TypeID是通过Internet上的研究确定的(希望我对此的研究是正确的)。 I think the key might be the use of the KeyValuePair and assign the result to ParentID. 我认为关键可能是使用KeyValuePair并将结果分配给ParentID。 This is my code on: 这是我的代码:
var list = new List<KeyValuePair<string, string>>() {
new KeyValuePair<string, string>("60", "f1d34cc0-9b50-4a78-be78-d5facfcccfb7"), };
listItem["Title"] = "do something";
listItem["ParentID"] = list;
listItem.Update();
context.ExecuteQuery();
The result I get or more precise the exception thrown is {"Unknown Error"}. 我得到或更准确地抛出异常的结果是{“ Unknown Error”}。
I am now clueless on where to turn to, or what to do next, do you have an idea? 我现在不知道该去哪里,或者下一步该怎么做? Is the idea of the KeyValuePair even the right one? KeyValuePair的想法是否正确?
Sample code for your reference. 示例代码供您参考。
using (var clientContext = new ClientContext(siteUrl))
{
clientContext.Credentials = new SharePointOnlineCredentials(login, securePassword);
List myList = clientContext.Web.Lists.GetByTitle("MyTask");
ListItemCreationInformation listItemCreationInformation = new ListItemCreationInformation();
ListItem newItem = myList.AddItem(listItemCreationInformation);
newItem["Title"] = "subTask";
newItem["Body"] = "body";
FieldLookupValue lookupParent = new FieldLookupValue();
//hardcode for test purpose
lookupParent.LookupId = 3;
newItem["ParentID"] = lookupParent;
newItem.Update();
clientContext.ExecuteQuery();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.