//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 .