TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Guruprakash C
NA
142
27.9k
Download files from google drive and save to a folder
Feb 16 2018 1:05 AM
Hi,
I need to download files from google drive and save to a folder on local using C#.
I have done as described in Google Developer API documentation (https://developers.google.com/drive/v3/web/manage-downloads) but i'm getting the file with invalid format. Please suggest how to download it.
I done:
downloadUrl = url of the file (eg: https://drive.google.com/uc?id=1ULNeKdDoCRmWgPPBW8-d1EGUZgqvA1Ul&export=download)
filename = some name with extension
private
bool
SaveToDir(
string
downloadUrl,
string
filename) {
string
filePath = Server.MapPath(
"imports/"
);
bool
resp =
false
;
DriveService ds =
new
DriveService();
Uri temp =
new
Uri(downloadUrl);
string
fileId = HttpUtility.ParseQueryString(temp.Query).Get(
"id"
);
var req = ds.Files.Get(fileId.Trim());
var stream =
new
MemoryStream();
req.MediaDownloader.ProgressChanged += (Google.Apis.Download.IDownloadProgress dp)=> {
switch
(dp.Status)
{
case
Google.Apis.Download.DownloadStatus.Downloading:
Message(
"downloading, please wait...."
);
break
;
case
Google.Apis.Download.DownloadStatus.Completed:
using
(FileStream file =
new
FileStream(filePath, FileMode.Create, FileAccess.Write))
{
stream.WriteTo(file);
Message(
"File Downloaded successfully."
);
}
resp =
true
;
break
;
case
Google.Apis.Download.DownloadStatus.Failed:
Message(
"Failed to Download."
);
resp =
false
;
break
;
}
};
req.Download(stream);
Attachment:
Default-aspx-cs.zip
Reply
Answers (
1
)
can't references System.Data libraries
Error Out of memory when dealing with tiff images in c# 2015