Shebin Shebin - 18 days ago 7
ASP.NET (C#) Question

Download file from google drive using c# without google API

As per the requirement ,the client is provide with an exe-(which contains the url of file to be downloaded) If we use the google api, we need to provide additional references along with the exe. It is not allowed by the client.

I used the webclient to download the file, but its downloading the file with doc type as HTML. My requirement is to download the file form google drive without using google API. Is there any way to do that?

I have tried the code as below

WebClient wb = new WebClient();
wb.DownloadFile("https://drive.google.com/file/d/0BzpAdEg-KyDjNVVSb0FBOWQ4V0k/view?usp=sharing", @"C:\TFS\test\test.pdf");


Result as shown below

enter image description here

Answer

This should help you.

Below is the standard sharing url for google drive.

https://drive.google.com/file/d/FILE_ID/edit?usp=sharing

the format you need to use for direct downloads is:

https://drive.google.com/uc?export=download&id=FILE_ID

this will link directly to the file instead of to the drive view in your current example.

so, for example, if your sharing url is https://drive.google.com/file/d/ABCDEFG1234567/edit?usp=sharing

then your direct download url is https://drive.google.com/uc?export=download&id=ABCDEFG1234567

Note, this is only for files you have uploaded yourself that were not created in drive itself (ie, doc, presentation, spreadsheet) using the google docs. to do that the format changes (will update answer if you need it)