title: How to upload a large file to Sharepoint drive with VB.Net using Microsoft Graph API?
body: <p>I'm trying to upload a large file (&gt; 4 MB) to a Sharepoint drive using VB.Net and the Microsoft Graph API. For testing purposes I aim for the root of the drive. Later on I will specify a subfolder.
  This is the code I use:</p>
  <pre><code>Public Shared Async Function UploadToFolder(ByVal driveId As String) As Task(Of DriveItem)
          Dim resultDriveItem As DriveItem = Nothing
          Try
              Using fileStream As New IO.FileStream(fileLocation, IO.FileMode.Open, IO.FileAccess.Read)
                  Dim uploadSession As UploadSession = Await GraphClient.Drives(driveId).Root.ItemWithPath(&quot;test.pdf&quot;).CreateUploadSession().Request().PostAsync()
                  Dim maxSlice As Integer = 320 * 1024
                  Dim largeFileUpload As New LargeFileUploadTask(Of DriveItem)(uploadSession, fileStream, maxSlice)
                  Dim uploadResult As UploadResult(Of DriveItem) = Await largeFileUpload.UploadAsync() 'error occurs here
                  resultDriveItem = uploadResult.ItemResponse
              End Using
          Catch ex As Exception
              Stop
          End Try
          Return resultDriveItem
      End Function
  </code></pre>
  <p>Unfortunately an error occurs at Await largeFileUpload.UploadAsync(). When I look at the error message, it doesn't make much sense:</p>
  <pre><code>Code: generalException
  Message: An error occurred sending the request.
  </code></pre>
  <p>On top of that the stacktrace doesn't help me any further either.</p>
  <pre><code>   bij Microsoft.Graph.SimpleHttpProvider.&lt;SendRequestAsync&gt;d__13.MoveNext()
  --- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
     bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     bij System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
     bij Microsoft.Graph.SimpleHttpProvider.&lt;SendAsync&gt;d__10.MoveNext()
  --- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
     bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     bij System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
     bij Microsoft.Graph.UploadSliceRequest`1.&lt;SendRequestAsync&gt;d__18.MoveNext()
  --- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
     bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     bij System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
     bij Microsoft.Graph.UploadSliceRequest`1.&lt;PutAsync&gt;d__17.MoveNext()
  --- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
     bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     bij System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
     bij Microsoft.Graph.LargeFileUploadTask`1.&lt;UploadSliceAsync&gt;d__14.MoveNext()
  --- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
     bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     bij System.Runtime.CompilerServices.ConfiguredTaskAwaitable`1.ConfiguredTaskAwaiter.GetResult()
     bij Microsoft.Graph.LargeFileUploadTask`1.&lt;UploadAsync&gt;d__16.MoveNext()
  --- Einde van stacktracering vanaf vorige locatie waar uitzondering is opgetreden ---
     bij System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
     bij System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
     bij System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
     bij Office365.Office365.VB$StateMachine_12_UploadToFolder.MoveNext() in C:\Note-books\Projects 2013\SharedTools\Tools\Office365\Office365.vb:regel 294
  </code></pre>
  <p>The thing is that I can upload a smaller file (with PutAsync) or do other stuff (create folder, list folder content, ...). Therefor I'm sure the authentication of the GraphClient is set okay.</p>
  <p>What am I doing wrong? Can anyone help, please?</p>
  <p>Stefan</p>