2017-06-23 4 views

答えて

0

あなたはここにファイルを作成するためのスニペットですか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; 
     } 
関連する問題