简体   繁体   English

使用c#(使用Microsoft.SharePoint.Client)将子任务添加到在线共享点中的任务中

[英]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]}&nbsp;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.

相关问题 如何在不使用Microsoft.SharePoint.Client和Microsoft.SharePoint.Client.Runtime之类的DLL的情况下使用c#创建共享点列表? - how can I create sharepoint lists using c# without using DLLs like Microsoft.SharePoint.Client and Microsoft.SharePoint.Client.Runtime? 使用 Microsoft.SharePoint.Client 将图像上传到共享点文件夹 - Uploading Image using Microsoft.SharePoint.Client to a sharepoint folder 使用Microsoft.SharePoint.Client从OneDrive下载文件 - download file from OneDrive using Microsoft.SharePoint.Client 使用Microsoft.SharePoint.Client按内容搜索项目 - Searching items by content using Microsoft.SharePoint.Client Microsoft.SharePoint.Client命名空间 - 无法识别Sharepoint命名空间 - Microsoft.SharePoint.Client namespace— Sharepoint namespace not recognized 尝试使用Visual Studio 2017将现有网站列添加到自定义列表| (Sharepoint)[Microsoft.Sharepoint.Client] - Trying to add existing site column to the custom list using Visual Studio 2017 | (Sharepoint) [Microsoft.Sharepoint.Client] 是否可以使用Microsoft.SharePoint.Client以编程方式获取Sharepoint网站的时区? - Is it possible to get the timezone of a Sharepoint site programmatically using Microsoft.SharePoint.Client? 有没有办法使用Microsoft.SharePoint.Client命名空间与其他用户创建新的列表项 - Is there a way to create a new list item with other user using Microsoft.SharePoint.Client namespace 尝试使用参考Microsoft.Sharepoint.Client添加新列表项时出现的问题 - Issues when trying to add new list items using the reference Microsoft.Sharepoint.Client 使用 C# 为 Sharepoint 创建在线项目 - Creating a Project Online using C# for Sharepoint
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM