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

Last Reply one year ago By kalpesh

Posted one year ago


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ASPSnippets.GoogleAPI;
using System.Web.Script.Serialization;

public partial class GoogleDriveFile : System.Web.UI.Page
    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; }
    protected void Page_Load(object sender, EventArgs e)
        GoogleConnect.ClientId = "222034134303-uadhf8i73dtbmh7dnt6l6380p6dltj86.apps.googleusercontent.com";
        GoogleConnect.ClientSecret = "XAUULTL-5UgEITuwugXjRR_H";
        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;
Line 30:             GoogleDriveFile file = (new JavaScriptSerializer()).Deserialize<GoogleDriveFile>(json);
Posted one year ago
Hi @Gita,
Please try the following

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

It might help you.

Cheers Andrea.

Posted one year ago

I am getting the below exception:

{"Ambiguous match found."}

Posted one year ago

mismatch in json file

Posted one year ago

What value you are getting for json variable.
Please share it so can analyze if there is problem for your class GoogleDriveFile to any property column value for error.