Microsoft graph api 如何使用Graph.NET SDK访问OneDrive应用程序文件夹
我想使用Graph.Net SDK在应用程序文件夹中创建一个文件。Microsoft graph api 如何使用Graph.NET SDK访问OneDrive应用程序文件夹,microsoft-graph-api,Microsoft Graph Api,我想使用Graph.Net SDK在应用程序文件夹中创建一个文件。 我可以找到一个类SpecialFolder,但我无法确定如何使用该类在应用程序文件夹中创建文件。您可以在 以下是创建文件的代码段: // Create a text file in the current user's root directory. public async Task<List<ResultsItem>> CreateFile(GraphServiceClient gra
我可以找到一个类SpecialFolder,但我无法确定如何使用该类在应用程序文件夹中创建文件。您可以在 以下是创建文件的代码段:
// Create a text file in the current user's root directory.
public async Task<List<ResultsItem>> CreateFile(GraphServiceClient graphClient)
{
List<ResultsItem> items = new List<ResultsItem>();
// Create the file to upload. Read the file content string into a stream that gets passed as the file content.
string guid = Guid.NewGuid().ToString();
string fileName = Resource.File + guid.Substring(0, 8) + ".txt";
byte[] byteArray = Encoding.ASCII.GetBytes(Resource.FileContent_New);
using (MemoryStream fileContentStream = new MemoryStream(byteArray))
{
// Add the file.
DriveItem file = await graphClient.Me.Drive.Root.ItemWithPath(fileName).Content.Request().PutAsync<DriveItem>(fileContentStream);
if (file != null)
{
// Get file properties.
items.Add(new ResultsItem
{
Display = file.Name,
Id = file.Id,
Properties = new Dictionary<string, object>
{
{ Resource.Prop_Created, file.CreatedDateTime.Value.ToLocalTime() },
{ Resource.Prop_Url, file.WebUrl },
{ Resource.Prop_Id, file.Id }
}
});
}
}
return items;
}
//在当前用户的根目录中创建一个文本文件。
公共异步任务创建文件(GraphServiceClient graphClient)
{
列表项=新列表();
//创建要上载的文件。将文件内容字符串读取到作为文件内容传递的流中。
字符串guid=guid.NewGuid().ToString();
字符串文件名=Resource.File+guid.Substring(0,8)+“.txt”;
byte[]byteArray=Encoding.ASCII.GetBytes(Resource.FileContent\u New);
使用(MemoryStream fileContentStream=新的MemoryStream(byteArray))
{
//添加文件。
DriveItem file=wait graphClient.Me.Drive.Root.ItemWithPath(文件名).Content.Request().PutAsync(fileContentStream);
如果(文件!=null)
{
//获取文件属性。
items.Add(新结果项)
{
Display=file.Name,
Id=file.Id,
属性=新字典
{
{Resource.Prop_Created,file.CreatedDateTime.Value.ToLocalTime()},
{Resource.Prop_Url,file.WebUrl},
{Resource.Prop_Id,file.Id}
}
});
}
}
退货项目;
}