[英]Exception on programmatically create new DocumentSet [SharePoint]
[英]Create and Manage Sharepoint DocumentSet with MS Graph
我找不到使用 MS 图形在 Sharepoint 库中创建文档集的任何方法。 有没有办法做到这一点? 任何帮助都非常感谢
AFAIK,今天没有直截了当的 API 可以用来实现这一目标。 话虽如此,你可以试试这个锻炼,看看这是否有帮助 -
GET 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);
希望这可以帮助某人
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.