【发布时间】:2021-05-22 15:12:30
【问题描述】:
我找不到使用 MS 图形在 Sharepoint 库中创建文档集的任何方法。有没有办法做到这一点?任何帮助都非常感谢
【问题讨论】:
标签: c# .net sharepoint microsoft-graph-api
我找不到使用 MS 图形在 Sharepoint 库中创建文档集的任何方法。有没有办法做到这一点?任何帮助都非常感谢
【问题讨论】:
标签: c# .net sharepoint microsoft-graph-api
AFAIK,今天没有直接的 API 可以用来实现这一点。 话虽如此,你可以试试这个锻炼,看看是否有帮助 -
获取https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}?$expand=drive
发布https://graph.microsoft.com/v1.0/drives/${library.drive.id}/root/children
请求正文
{
"name": "New Folder name",
"folder": {},
"@microsoft.graph.conflictBehavior": "rename"
}
4.更新文档库中的项目,使其更新为所需的文档集。
补丁https://graph.microsoft.com/v1.0/sites/${siteId}/lists/${listId}/items/${sharepointIds.listItemId}
请求正文
{
"contentType": {
"id": "content-type-id-of-the-document-set"
},
"fields": {
//fields that you wish to set
}
}
【讨论】:
我能够通过以下方式完成此操作,抱歉没有更新eariler:
变量:
SpURL = "site.sharepoint.com";
SiteURL = "/sites/myTestSite";
LibraryName = "Library";
ContentType = "mycontenttype";
1- 按路径获取站点 ID:
var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
var site = await client.Sites.GetByPath(siteURL, spURL).Request().GetAsync();
return site.Id;
2- 按路径的驱动器 ID:
var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
var request = client.Sites[siteID].Drives.Request();
var result = await request.GetAsync();
//.Filter is not working here for some reasone
var filter = result?.Where(x => x.Name.Contains(LibraryName)).ToList();
if (filter.Count > 0) {
return filter.First().Id;
}
else {
return "";
}
3- 获取列表 ID:
var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
var request = client.Sites[siteID].Lists.Request().Filter($"displayName eq '{ListName}'");
var result = await request.GetAsync();
return result.First().Id;
var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
var request = client.Sites[siteID].Lists.Request().Filter($"displayName eq '{ListName}'");
var result = await request.GetAsync();return result.First().Id;
var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
var folder = new DriveItem
{
Name = foldername,
Folder = new Microsoft.Graph.Folder(),
AdditionalData = new Dictionary<string, object>()
{
{"@microsoft.graph.conflictBehavior", "rename"}
},
};
var folderObj = await client.Drives[driveID].Root.Children.Request().AddAsync(folder);
return folderObj.Id;
//Save folderID from the above return
var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
var request = client.Sites[siteID].Lists[listID].ContentTypes.Request().Filter($"name eq '{contentTypeName}'");
var result = await request.GetAsync();
return result.First().Id;
var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
var request = client.Sites[siteID].Drives[driveID].Items[folderID].Request().Select("sharepointIds");
var result = await request.GetAsync();
return result.SharepointIds.ListItemId;
var scopes = new string[] { ISD.MicrosoftGraph.Constants.ScopeDefault };
var client = GraphServiceClientFactory.GetAuthenticatedGraphClient(() => AcquireAppToken(scopes), "https://graph.microsoft.com/beta");
var listItem = new Microsoft.Graph.ListItem
{
Fields = new FieldValueSet
{
AdditionalData = new Dictionary<string, object>()
{
{"Country", "Palestine"},
{ "My_x0020_Field", "2000"}//Custom field with spaces
}
}
, ContentType = new ContentTypeInfo() {
Id = "0x5465424879454894654564654F300A1C2CDC00E306F9F19B9654654654654" //this is a sample content type id acquired in step 6
}
};
var request = client.Sites[siteID].Lists[listID].Items[listItemID].Request();
var result = await request.UpdateAsync(listItem);
希望这对某人有所帮助
【讨论】: