title: Google Drive and .NET WinForms
body: <p>Cannot connect my Windows Form Application with GoogleDrive via Drive API. </p>
  
  <p>I have created a project on <a href="https://console.developers.google.com/" rel="nofollow">https://console.developers.google.com/</a>, enabled Drive API, generated Client ID, Service e-mail and *.p12 key.</p>
  
  <p>I instantiate DriveService by this method:</p>
  
  <pre><code>private const string SERVICE_ACCOUNT_EMAIL = "SERVICE_EMAIL@developer.gserviceaccount.com";
  private const string SERVICE_ACCOUNT_PKCS12_FILE_PATH = @"PATH_.p12";
  
  static DriveService BuildService()
  {
      X509Certificate2 certificate = new X509Certificate2(SERVICE_ACCOUNT_PKCS12_FILE_PATH, "notasecret", X509KeyStorageFlags.Exportable);
  
      ServiceAccountCredential credential = new ServiceAccountCredential(
      new ServiceAccountCredential.Initializer(SERVICE_ACCOUNT_EMAIL)
      {
          User = "OWNER_EMAIL@GMAIL.COM",
          Scopes = new[] { DriveService.Scope.DriveFile }
      }.FromCertificate(certificate));
  
      var service = new DriveService(new BaseClientService.Initializer()
      {
          HttpClientInitializer = credential,
          ApplicationName = "Drive API Sample",
      });
  
      return service;
  }
  </code></pre>
  
  <p>And try to upload files by this method:</p>
  
  <pre><code>public static void upload(String filepath)
  {
      File body = new File();
      body.Title = "test";
      body.Description = "Some description";
      body.MimeType = "text/plain";
  
      byte[] byteArray = System.IO.File.ReadAllBytes(filepath);
      System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
  
      FilesResource.InsertMediaUpload request = BuildService().Files.Insert(body, stream, "text/plain");
      request.Upload();
  
      File file = request.ResponseBody;
  }
  </code></pre>
  
  <p>However, request.ResponceBody is always null. What do I miss ?</p>