upload a file into gdrive using c#
// this code snippet helps you to upload a file into a specific folder in gdrive
public static void Upload()
{
DocumentsService service = new DocumentsService("My Upload Application");
ClientLoginAuthenticator authenticator = new ClientLoginAuthenticator("My C\Upload Application", ServiceNames.Documents, "YouremailID", "YourPassword");
DocumentEntry entry = new DocumentEntry();
entry.MediaSource = new MediaFileSource(@"c:\newfolder\newtext.txt","text/plain");
Uri createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full/folder%3A"+ResourceId+"/contents?convert=false");// Resource Id is the id of a folder in the gdrive.
//Uri createUploadUrl = new Uri("https://docs.google.com/feeds/upload/create-session/default/private/full");//upload into root folder
AtomLink link = new AtomLink(createUploadUrl.AbsoluteUri);
link.Rel = ResumableUploader.CreateMediaRelation;
entry.Links.Add(link);
// Set the service to be used to parse the returned entry
entry.Service = service;
// Instantiate the ResumableUploader component.
ResumableUploader uploader = new ResumableUploader();
// Set the handlers for the completion and progress events
uploader.AsyncOperationCompleted += new AsyncOperationCompletedEventHandler(OnDone);
uploader.AsyncOperationProgress += new AsyncOperationProgressEventHandler(OnProgress);
// Start the upload process
uploader.InsertAsync(authenticator, entry, new object());
}
static void OnDone(object sender, AsyncOperationCompletedEventArgs e)
{
DocumentEntry entry = e.Entry as DocumentEntry;
}
static void OnProgress(object sender, AsyncOperationProgressEventArgs e)
{
int percentage = e.ProgressPercentage;
}
Post a Comment
1 Comments
Super Thank you
ReplyDelete