Click here to Skip to main content
16,019,018 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
//TO:DO
var fileName = System.IO.Path.GetFileName(file.FileName);
var path = System.IO.Path.Combine(Server.MapPath("~/Content/Upload"), fileName);
file.SaveAs(path);
ModelState.Clear();
UserCredential credential = GoogleWebAuthorizationBroker.AuthorizeAsync(
new ClientSecrets
{
ClientId = ClientId,
ClientSecret = ClientSecret,
},
new[] { DriveService.Scope.Drive },
"user",
CancellationToken.None).Result;

// 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");
request.Upload();

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 .
Posted
Updated 1-Feb-17 18:18pm
v2
Comments
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 asp.net C#.
Please reply immediately.

1 solution

Check out the online help for this https://developers.google.com/drive/[^]
 
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