0
Graph .Net SDKを使用してアプリケーションフォルダにファイルを作成します。 私はクラスSpecialFolderを見つけることができますが、クラスを使用してアプリケーションフォルダ内にファイルを作成する方法を練習することができません。Graph .NET SDKを使用してOneDriveアプリケーションフォルダにアクセスするには
Graph .Net SDKを使用してアプリケーションフォルダにファイルを作成します。 私はクラスSpecialFolderを見つけることができますが、クラスを使用してアプリケーションフォルダ内にファイルを作成する方法を練習することができません。Graph .NET SDKを使用してOneDriveアプリケーションフォルダにアクセスするには
あなたはここにファイルを作成するためのスニペットですかaspnet-snippets-sample
にSDKを使用するサンプルの収集を見つけることができます。
// 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;
}