title: How to upload to OneDrive using Microsoft Graph Api in c#
body: <p>I have been trying to upload to a OneDrive account and I am hopelessly stuck not being able to upload neither less or greater than 4MB files. I have no issues accessing the drive at all, since I have working functions that create a folder, rename files/folders, and a delete files/folders. </p>
  
  <p><a href="https://docs.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&amp;tabs=csharp" rel="nofollow noreferrer">https://docs.microsoft.com/en-us/graph/api/driveitem-put-content?view=graph-rest-1.0&amp;tabs=csharp</a></p>
  
  <p>This documentation on Microsoft Graph API is very friendly to HTTP code, and I believe I am able to fairly "translate" the documentation to C#, but still fail to grab a file and upload to OneDrive. Some places online seem to be using byte arrays? Which I am completely unfamiliar with since my primary language is C++ and we just use ifstream/ofstream. Anyways, here is the portion of code in specific (I hope this is enough):</p>
  
  <pre><code>var item = await _client.Users[userID].Drive.Items[FolderID]//"01YZM7SMVOQ7YVNBXPZFFKNQAU5OB3XA3K"].Content
                      .ItemWithPath("LessThan4MB.txt")//"D:\\LessThan4MB.txt")
                      .CreateUploadSession()
                      .Request()
                      .PostAsync();
              Console.WriteLine("done printing");
  </code></pre>
  
  <p>As it stands, it uploads a temporary file that has a tilde "~" in the OneDrive (like as if I was only able to open but not import any data from the file onto it). If I swap the name of the file so it includes the file location it throws an error:</p>
  
  <p>Message: Found a function 'microsoft.graph.createUploadSession' on an open property. Functions on open properties are not supported.</p>
  
  <p>Thanks, any comments and help would mean a lot.</p>