简体   繁体   English

无法使用图sdk在Sharepoint中在线创建新列表

[英]Unable to create a new list in sharepoint online using graph sdk

I have backed up the list from my site and deleted some list from it. 我已经从网站备份了列表,并从中删除了一些列表。 Now I wanted to restore a List inside Site. 现在,我想在网站内恢复列表。

To restore list I used create List graph call(since the list was deleted) and passed all the data from the list that I backed up(excluding Name attribute). 要恢复列表,我使用了create List图调用(因为删除了列表),并传递了我备份的列表中的所有数据(不包括Name属性)。

The List that I passed as an argument is: 我作为参数传递的列表是:

displayName : "qwerty"
list
columns
contentTypes
createdBy
createdDateTime : "2019-08-07T15:26:45+05:30"
description : ""
eTag : ""4aa6af8e-32d6-4ca9-ac0a-02c8e110f65d,6""
lastModifiedDateTime : "2019-08-07T15:26:45+05:30"
name : null
parentReference
webUrl : "https://dextorlab.sharepoint.com/sites/HelloWorld/Lists/qwerty"
id : "4aa6af8e-32d6-4ca9-ac0a-02c8e110f65d"
@odata.etag : ""4aa6af8e-32d6-4ca9-ac0a-02c8e110f65d,6

The Graph Call that is made is: 进行的图形调用为:

var ListResult = _SharepointOperations._GraphCLient.Sites[_SiteId].Lists.Request().AddAsync(siteList).Result;

I expect the output as successful, but graph return "one or more errors occurred" with inner error as "Unable to determine type of provided column definition" 我期望输出成功,但是图形返回“发生一个或多个错误”,内部错误为“无法确定提供的列定义的类型”

You need format the siteList like below. 您需要像下面这样格式化siteList。

var siteList = new List
{
    DisplayName = "Books",
    Columns = new List<ColumnDefinition>()
    {
        new ColumnDefinition
        {
            Name = "Author",
            Text = new TextColumn
            {
            }
        },
        new ColumnDefinition
        {
            Name = "PageCount",
            Number = new NumberColumn
            {
            }
        }
    },
    List = new ListInfo
    {
        Template = "genericList"
    }
};

Article: Create a new list 文章: 创建一个新列表

To add items to the list using this. 使用此将项目添加到列表中。

GraphServiceClient graphClient = new GraphServiceClient( authProvider );

var listItem = new ListItem
{
    Fields = new FieldValueSet
    {
        Title = "Widget",
        Color = "Purple",
        Weight = 32
    }
};

await graphClient.Sites["{site-id}"].Lists["{list-id}"].Items
    .Request()
    .AddAsync(listItem);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM