title: Google Drive Api Integration in asp.net web application
body: <p>``I am creating  asp.net 4.0 web application. I have created ClientID and Client Secret . I want to authenticate user and upload  file in google drive from my web application.
  I have checked this link :-
  <a href="https://developers.google.com/drive/quickstart-cs" rel="nofollow">https://developers.google.com/drive/quickstart-cs</a>.</p>
  
  <p>But it is related to console application. 
  How can we upload our file using ASp.net web application?</p>
  
  <p>Here is code sample</p>
  
  <pre><code>protected void btnSubmit_Click(object sender, EventArgs e)
  {String CLIENT_ID = "XXXXX";
      String CLIENT_SECRET = "YYYYY";
  
      // Register the authenticator and create the service
      var provider = new NativeApplicationClient(GoogleAuthenticationServer.Description, CLIENT_ID, CLIENT_SECRET);
      var auth = new OAuth2Authenticator&lt;NativeApplicationClient&gt;(provider, GetAuthorization);
      var service = new DriveService(new BaseClientService.Initializer()
      {
          Authenticator = auth
      });
  
      File body = new File();
      body.Title = "My document";
      body.Description = "A test document";
      body.MimeType = "text/plain";
  
      //my code start
  
  
      //my code end
  
      byte[] byteArray = System.IO.File.ReadAllBytes(Server.MapPath("~/GoogleDrive/document.txt"));
      System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);
  
      FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "text/plain");
      request.Upload();
  
  
      File file = request.ResponseBody;
      Response.Write("File id: " + file.Id);
      Response.Write("Press Enter to end this process.");}
  private static IAuthorizationState GetAuthorization(NativeApplicationClient arg)
  {
      // Get the auth URL:
      IAuthorizationState state = new AuthorizationState(new[] { DriveService.Scopes.Drive.GetStringValue() });
      state.Callback = new Uri(NativeApplicationClient.OutOfBandCallbackUrl);
      Uri authUri = arg.RequestUserAuthorization(state);
  
      // Request authorization from the user (by opening a browser window):
      Process.Start(authUri.ToString());
      Console.Write("Authorization Code: ");
      string authCode = Console.ReadLine();
      Console.WriteLine();
  
      // Retrieve the access token by using the authorization code:
      return arg.ProcessUserAuthorization(authCode, state);
  }
  </code></pre>
  
  <p>Thanks in advance!!</p>