title: Upload file to Google Drive
body: <p>I need to upload files on my google drive (pdf, word, excel), how can I do it in ASP.NET using C#? Could you explain me step by step all the passages? If it can be useful I put my last test code:</p>
  
  <pre><code>using System;
  using System.Collections.Generic;
  using System.Linq;
  using System.Web.UI;
  using System.Web.UI.WebControls;
  using ASPSnippets.GoogleAPI;
  using System.Runtime.Serialization;
  using System.IO;
  using System.Web.Script.Serialization;
  
  ...
  
      protected void Page_Load(object sender, EventArgs e)
      {
          GoogleConnect.ClientId = "my_client_id";
          GoogleConnect.ClientSecret = "my_client_secret";
          GoogleConnect.RedirectUri = Request.Url.AbsoluteUri.Split('?')[0];
          GoogleConnect.API = EnumAPI.Drive;
          if (!string.IsNullOrEmpty(Request.QueryString["code"]))
          {
              string code = Request.QueryString["code"];
              string json = GoogleConnect.PostFile(code, (HttpPostedFile)Session["File"], Session["Description"].ToString());
              GoogleDriveFile file = (new JavaScriptSerializer()).Deserialize&lt;GoogleDriveFile&gt;(json);
              tblFileDetails.Visible = true;
              lblTitle.Text = file.Title;
              lblId.Text = file.Id;
              imgIcon.ImageUrl = file.IconLink;
              lblCreatedDate.Text = file.CreatedDate.ToString();
              lnkDownload.NavigateUrl = file.WebContentLink;
              if (!string.IsNullOrEmpty(file.ThumbnailLink))
              {
                  rowThumbnail.Visible = true;
                  imgThumbnail.ImageUrl = file.ThumbnailLink;
              }
          }
          if (Request.QueryString["error"] == "access_denied")
          {
              ClientScript.RegisterClientScriptBlock(this.GetType(), "alert", "alert('Access denied.')", true);
          }
      }
  
      protected void UploadFile(object sender, EventArgs e)
      {
          Session["File"] = FileUpload1.PostedFile;
          Session["Description"] = txtDescription.Text;
          GoogleConnect.Authorize("https://www.googleapis.com/auth/drive.file");
      }
  }
  
  
  public class GoogleDriveFile
  {
      public string Id { get; set; }
      public string Title { get; set; }
      public string OriginalFilename { get; set; }
      public string ThumbnailLink { get; set; }
      public string IconLink { get; set; }
      public string WebContentLink { get; set; }
      public DateTime CreatedDate { get; set; }
      public DateTime ModifiedDate { get; set; }
  }
  </code></pre>
  
  <p>But I have this error:</p>
  
  <blockquote>
    <ol start="400">
    <li>That’s an error.</li>
    </ol>
    
    <p>Error: redirect_uri_mismatch</p>
    
    <p>The redirect URI in the request, <a href="http://localhost:61360/Prova.aspx" rel="nofollow noreferrer">http://localhost:61360/Prova.aspx</a>,
    does not match the ones authorized for the OAuth client. Visit
    <a href="https://console.developers.google.com/apis/credentials/oauthclient/831126948299-2bopcsp3aee3harncqp5dpkq77sii3he.apps.googleusercontent.com?project=831126948299" rel="nofollow noreferrer">https://console.developers.google.com/apis/credentials/oauthclient/831126948299-2bopcsp3aee3harncqp5dpkq77sii3he.apps.googleusercontent.com?project=831126948299</a>
    to update the authorized redirect URIs.</p>
  </blockquote>
  
  <p>Request Details:</p>
  
  <blockquote>
  <pre><code>scope=https://www.googleapis.com/auth/drive.file
  redirect_uri=http://localhost:61360/Prova.aspx
  response_type=code
  client_id=831126948299-2bopcsp3aee3harncqp5dpkq77sii3he.apps.googleusercontent.com
  approval_prompt=auto
  access_type=offline
  </code></pre>
  </blockquote>
  
  <p>I've insert the redirect page but it gave me the same error.</p>