當使用files = await graphClient.Me.Drive.Root.ItemWithPath(Path).Children.Request().GetAsync();
如何將下載的文件保存到指定的路徑?
文件下載的得到保存在C:\Users\someone\AppData\Local\Packages\4a9bc9b3-6484-4443-9a65-f36f7519b1d5_9b10f1p8kdmhr\AC\INetCache\3HUY71XE
public static async Task<System.IO.Stream > GetCurrentUserFileAsync(string Path, string FileName)
{
IDriveItemChildrenCollectionPage files = null;
try
{
var graphClient = AuthenticationHelper.GetAuthenticatedClient();
files = await graphClient.Me.Drive.Root.ItemWithPath(Path).Children.Request().GetAsync();
foreach (DriveItem item in files)
{
Debug.WriteLine("Got file: " + item.Name);
if (item.Name == FileName)
{
var fileContent = await DownloadFileAsync(item.Id);
return fileContent ;
}
}
return null;
}
catch (ServiceException e)
{
Debug.WriteLine("We could not get user files: " + e.Error.Message);
return null;
}
}
// Downloads the content of an existing file.
public static async Task<Stream> DownloadFileAsync(string fileId)
{
Stream fileContent = null;
try
{
var graphClient = AuthenticationHelper.GetAuthenticatedClient();
var downloadedFile = await graphClient.Me.Drive.Items[fileId].Content.Request().GetAsync();
fileContent = downloadedFile;
Debug.WriteLine("Downloaded file content for file: " + fileId);
}
catch (ServiceException e)
{
Debug.WriteLine("We could not download the file. The request returned this status code: " + e.Error.Message);
return null;
}
return fileContent;
}
DownloadFileAsync的定義是什麼? –