无法通过图表使用 C# 示例为共享点创建列表 API
can't create List for sharepoint using C# sample via graph API
参考图表 API v1.0 文档 -> Create List section
我在我的代码中添加下面的 C# 示例来创建列表:
var list = new List
{
DisplayName = "Books",
Columns = new List<ColumnDefinition>()
{
new ColumnDefinition
{
Name = "Author",
Text = new TextColumn
{
}
},
new ColumnDefinition
enter code here
{
Name = "PageCount",
Number = new NumberColumn
{
}
}
},
`List = new ListInfo`
`{`
`Template = "genericList"`
`}`
};
await graphClient.Sites["{site-id}"].Lists.Request().AddAsync(list);
但出现以下错误:
Cannot implicitly convert type
'System.Collections.Generic.List' to
'Microsoft.Graph.IListColumnsCollectionPage'.
enter image description here
通过图表创建 List 的正确 C# 应该是什么 API?
测试代码基于this project。
var graphServiceClient = GraphClientFactory.GetGraphServiceClient(config.ClientId, config.Authority, config.Scopes);
if (graphServiceClient != null)
{
List<ColumnDefinition> listOfCols = new List<ColumnDefinition>() {
new ColumnDefinition
{
Name = "Author",
Text = new TextColumn
{
}
},
new ColumnDefinition
{
Name = "PageCount",
Number = new NumberColumn
{
}
}
};
ListColumnsCollectionPage columns = new ListColumnsCollectionPage();
foreach (ColumnDefinition item in listOfCols)
{
columns.Add(item);
}
List list = new List
{
DisplayName = "TestGraph",
Columns = columns,
ListInfo = new ListInfo
{
Template = "genericList"
}
};
await graphServiceClient.Sites["tenant.sharepoint.com,x-b669-4537-b0f5-x,x-e306-407b-b1a2-x"].Lists
.Request()
.AddAsync(list);
Console.WriteLine("----");
}
参考图表 API v1.0 文档 -> Create List section
我在我的代码中添加下面的 C# 示例来创建列表:
var list = new List
{
DisplayName = "Books",
Columns = new List<ColumnDefinition>()
{
new ColumnDefinition
{
Name = "Author",
Text = new TextColumn
{
}
},
new ColumnDefinition
enter code here
{
Name = "PageCount",
Number = new NumberColumn
{
}
}
},
`List = new ListInfo`
`{`
`Template = "genericList"`
`}`
};
await graphClient.Sites["{site-id}"].Lists.Request().AddAsync(list);
但出现以下错误:
Cannot implicitly convert type 'System.Collections.Generic.List' to 'Microsoft.Graph.IListColumnsCollectionPage'.
enter image description here
通过图表创建 List 的正确 C# 应该是什么 API?
测试代码基于this project。
var graphServiceClient = GraphClientFactory.GetGraphServiceClient(config.ClientId, config.Authority, config.Scopes);
if (graphServiceClient != null)
{
List<ColumnDefinition> listOfCols = new List<ColumnDefinition>() {
new ColumnDefinition
{
Name = "Author",
Text = new TextColumn
{
}
},
new ColumnDefinition
{
Name = "PageCount",
Number = new NumberColumn
{
}
}
};
ListColumnsCollectionPage columns = new ListColumnsCollectionPage();
foreach (ColumnDefinition item in listOfCols)
{
columns.Add(item);
}
List list = new List
{
DisplayName = "TestGraph",
Columns = columns,
ListInfo = new ListInfo
{
Template = "genericList"
}
};
await graphServiceClient.Sites["tenant.sharepoint.com,x-b669-4537-b0f5-x,x-e306-407b-b1a2-x"].Lists
.Request()
.AddAsync(list);
Console.WriteLine("----");
}