【发布时间】:2022-07-29 16:24:58
【问题描述】:
我有一种情况,我需要以编程方式将文件夹及其所有子文件夹(包括它们的子文件夹)创建到共享点文档库中。 是否有可能在 1 次通话中做到这一点?
现在我一个文件夹一个文件夹地做,因为有很多子文件夹,这确实需要相当长的时间。这是我的做法:
//newFolder - The folder that i want to create, contains subfolders
//destinationFolder - The destination folder where i want to create newFolder
public void createFolder(ExternalDocumentFolder newFolder, ExternalDocumentFolder destinationFolder) {
GraphServiceClient<Request> graphClient = graphServiceClientBuilder.buildForNoUser();
String driveID = getDriveID(graphClient);
//All subfolders are flattened into a single list for easy of saving
List<ExternalDocumentFolder> externalDocumentFolders = flattenFolder(newFolder);
for (ExternalDocumentFolder folder : externalDocumentFolders) {
DriveItem newDriveItem = mapToDriveItem(folder);
String destinationPath = destinationFolder.getPath();
if(folder.getParent() != null){
destinationPath = destinationPath + "/" + folder.getParent().getPath();
}
DriveItem returnedDriveItem = graphClient.drives(driveID).items("root:/" + destinationPath + ":").children().buildRequest().post(newDriveItem);
}
}
【问题讨论】:
-
您可以使用批处理请求将所有请求合并到一个调用中。请检查此document。
-
@ShivaKeshavVarma 它奏效了。如果你愿意,请回答我可以接受它
-
很高兴听到它对您有用。 :)
标签: java spring sharepoint microsoft-graph-api directory-structure