Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Download file from google drive using c# without google API

Tags:

c#

asp.net

exe

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

like image 547
Shebin Avatar asked Jan 28 '16 08:01

Shebin


People also ask

How do I move files from Google Drive to C drive?

Drag files into Google Drive On your computer, go to drive.google.com. Open or create a folder. To upload files and folders, drag them into the Google Drive folder.

Can I download a file directly to Google Drive?

On your iOS or Android devices, open the Google Drive app. Tap Upload. Find and tap the files you want to upload. View uploaded files in My Drive until you move them to another folder.


1 Answers

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)

Edit:

It is worth noting that if the files location changes then the url and direct download link will change too, meaning you will need to update it.

like image 81
Takarii Avatar answered Sep 28 '22 08:09

Takarii