Click here to Skip to main content
15,746,813 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
var fileName = System.IO.Path.GetFileName(file.FileName);
var path = System.IO.Path.Combine(Server.MapPath("~/Content/Upload"), fileName);
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
ClientId = ClientId,
ClientSecret = ClientSecret,
new[] { DriveService.Scope.Drive },

// Create the service.
var service = new DriveService(new BaseClientService.Initializer()
HttpClientInitializer = credential,
ApplicationName = APIID,

File body = new File();
body.Title = "Candidates Document-" + System.IO.Path.GetFileNameWithoutExtension(file.FileName);
body.Description = "Carrer document";
body.MimeType = "application/msword";

byte[] byteArray = System.IO.File.ReadAllBytes(path);
System.IO.MemoryStream stream = new System.IO.MemoryStream(byteArray);

FilesResource.InsertMediaUpload request = service.Files.Insert(body, stream, "application/msword");

File driveFile = request.ResponseBody;

ViewBag.Message = "File uploaded successfully.File id: " + driveFile.Id;

This code working good. But I wont that I am admin User I have google drive .There are many user of my site they upload there document on my drive without any authentication
Please reply as soon as possible .
Updated 1-Feb-17 18:18pm
Rajib Mahata 31-Oct-14 8:34am    
actually I am developing Web Application to allow clients to upload file on my Google drive with automatic authentication.
Yash Pandey 11-Jul-16 10:13am    
How to upload image on google drive using MVC C#.
Please reply immediately.

1 solution

Check out the online help for this[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900