Upload Files to Google Drive using Google Drive API in ASP.Net with C# and VB.Net

Last Reply 5 days ago By dharmendr

Posted 5 days ago


using ASPSnippets.GoogleAPI;
using System.Web.Script.Serialization;
protected void Page_Load(object sender, EventArgs e)
    GoogleConnect.ClientId = "<Google Client ID>";
    GoogleConnect.ClientSecret = "<Google 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<GoogleDriveFile>(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;

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; }

iam unable to connect google drive in Page load  what is code i have given Client ID and Client secret    but iam not getting code what is that

You are viewing reply posted by: dharmendr 5 days ago.
Posted 5 days ago

Hi ysairam17,

In order to use Google Drive API for uploading files to Google Drive, you will need to create an Application in Google Console and get Client ID and Client Secret. And pass the Client ID and Client Secret in page load in place of <Google Client ID> and <Google Client Secret>

For details please refer the following article.

Google Developer Console: Generate Client ID and Client Secret for use with Google APIs

I agree, here is the link: http://e-iceblue.com/free-api