title: Google REST API Download
body: <p>I am struggling with getting data from Google Drive.</p>
  
  <p>I am using Google Drive API v3 with this code:</p>
  
  <pre><code>Imports System.Security.Cryptography.X509Certificates
  Imports System
  Imports System.Threading
  Imports System.Threading.Tasks
  Imports System.IO
  Imports System.Linq
  Imports System.Text
  
  Imports Google.Apis.Auth.OAuth2
  Imports Google.Apis.Drive.v3
  Imports Google.Apis.Drive.v3.Data
  Imports Google.Apis.Services
  Imports Google.Apis.Util.Store
  
  
  Public Class DownloadMe
      Inherits System.Web.UI.Page
  
      Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
  
      End Sub
  
      Protected Sub btn0_Click(sender As Object, e As EventArgs) Handles btn0.Click
          DownloadMe()
      End Sub
  
      Protected Sub DownloadMe()
          Dim fileID As String = "someFileID"
          Dim driveService As New DriveService
          Dim request = driveService.Files.Export(fileID, "text/plain")
          'Dim request = driveService.Files.Get(fileID)
  
          Dim dir As String = "C:\Users\JohnDoe\Documents\Visual Studio 2012\Projects\GoogleDriveDownload\"
          Dim output As String = dir + "test.txt"
          Dim stream As New System.IO.MemoryStream
  
          Try
              request.Download(stream)
              If System.IO.File.Exists(output) Then
                  System.IO.File.Delete(output)
              End If
  
              Dim fs As New FileStream(output, FileMode.Create, FileAccess.Write)
              stream.WriteTo(fs)
  
              stream.Close()
              fs.Close()
  
          Catch ex As Exception
              MyCompany.Diagnostics.Log("An error occured: " + ex.Message)
              lit0.Text = "An error occured: " + ex.Message + "&lt;br /&gt;"
          End Try
  
      End Sub
  End Class
  </code></pre>
  
  <p>The problem is I am getting nothing in the stream, so the created "text.txt" file is a blank file instead of the typical "Lorem ipsum..." text.</p>
  
  <p>Any clue on how to remedy this?</p>