问题
Google documents. I need edit a document with puplic link in c#. Is there anyway?
FileStream fs = FileStream("C:\*****.jpg", FileMode.Open);
DocumentEntry entry2 = service.Update(new Uri(strAlternateUriComesFromServer), fs, "text/plain", null) as DocumentEntry;
This code giving error. How can i edit public document.
i got only shared document link and i need to update it.
回答1:
If you know the document name or resourceID, and that document is shared with you, and you have the proper read/write access (ACL), you shouldn't have any problem updating the resource.
Normally updating a document with Google Documents API goes something like this:
Get the DocumentEntry for the document. You can construct a DocumentQuery to find the target document based on certain search parameters. See the documentation here: Google Documents List API 3.0
Get the download URL from the DocumentEntry object and download the document to your PC. Downloading is optional if you're not interested in modifying the original content and just want to upload and overwrite the contents with something you have made locally.
Edit the document and update (upload) it to Google Docs. Documentation for Updating. Specifically, look at the section called "Updating document or file content with the resumable protocol." You must use the ResumableUploader when uploading anything to Docs now.
Edit to add: Try to get the DocumentEntry from the public link using the method below:
// Public Link contains the resourceID
// example: https://docs.google.com/file/d/097iZigwrANhGTElvZDdCVmlZNzQ/edit
// resourceID: 097iZigwrANhGTElvZDdCVmlZNzQ
// Get Your Document Entry
string editUri = "http://docs.google.com/feeds/documents/private/full/%3A" + resourceID;
DocumentEntry docEntry = (DocumentEntry)service.Get(editUri);
回答2:
string editUri = "https://docs.google.com/feeds/default/private/full/file%3A" + resId;
DocumentEntry docEntry = (DocumentEntry)dsServ1.Get(editUri);
docEntry.Title.Text = strNewName;
docEntry.MediaSource = new MediaFileSource("C:\\new.txt", "text/plain");
ResumableUploader uploader = new ResumableUploader();
// Start the update process.
ClientLoginAuthenticator oa = new ClientLoginAuthenticator("Komote", ServiceNames.Documents, strUsername, strPassword);
uploader.UpdateAsync(oa, docEntry, new object());
This code works great. thanx for help.
来源:https://stackoverflow.com/questions/14395853/google-documents-i-need-to-edit-a-document-with-public-link-c-sharp