图API:修改目录内文件内容
Graph API: modify content of file inside directory
我正在尝试使用 .NET 将文件上传到某个 SharePoint 目录。到目前为止,我可以将它上传到根目录:
var fileItem = new DriveItem
{
Name = "test3.txt",
File = new Microsoft.Graph.File
{
},
AdditionalData = new Dictionary<string, object>()
{
{"@microsoft.graph.conflictBehavior", "rename"}
}
};
await graphClient
.Sites["*****.sharepoint.com"]
.Drive
.Root
.Children
.Request()
.AddAsync(fileItem);
var sites = await graphClient
.Sites["*****.sharepoint.com"]
.Drive
.Root
.Children["test3.txt"].Content.Request().PutAsync<DriveItem>(stream);
我可以在文件夹中创建文件:
await graphClient
.Sites["*****.sharepoint.com"]
.Drive
.Root.Children["New Folder3"]
.Children
.Request()
.AddAsync(fileItem);
但是当我尝试向该文件(目录内)添加内容时:
await graphClient
.Sites["*****.sharepoint.com"]
.Drive
.Root
.Children["New Folder3"]
.Children["test.txt"].Content.Request().PutAsync<DriveItem>(stream);
我捕捉到了 ResourceNotFoundException 异常。
您可以尝试使用'ItemWithPath'方法并按照 or it would be better giving the id rather than using the Folder name or file name and use it according to this document中所述指定路径。
我正在尝试使用 .NET 将文件上传到某个 SharePoint 目录。到目前为止,我可以将它上传到根目录:
var fileItem = new DriveItem
{
Name = "test3.txt",
File = new Microsoft.Graph.File
{
},
AdditionalData = new Dictionary<string, object>()
{
{"@microsoft.graph.conflictBehavior", "rename"}
}
};
await graphClient
.Sites["*****.sharepoint.com"]
.Drive
.Root
.Children
.Request()
.AddAsync(fileItem);
var sites = await graphClient
.Sites["*****.sharepoint.com"]
.Drive
.Root
.Children["test3.txt"].Content.Request().PutAsync<DriveItem>(stream);
我可以在文件夹中创建文件:
await graphClient
.Sites["*****.sharepoint.com"]
.Drive
.Root.Children["New Folder3"]
.Children
.Request()
.AddAsync(fileItem);
但是当我尝试向该文件(目录内)添加内容时:
await graphClient
.Sites["*****.sharepoint.com"]
.Drive
.Root
.Children["New Folder3"]
.Children["test.txt"].Content.Request().PutAsync<DriveItem>(stream);
我捕捉到了 ResourceNotFoundException 异常。
您可以尝试使用'ItemWithPath'方法并按照