0

谷歌文档。我需要在 c# 中编辑带有公共链接的文档。到底有没有?

FileStream fs = FileStream("C:\*****.jpg", FileMode.Open); 
DocumentEntry entry2 = service.Update(new Uri(strAlternateUriComesFromServer), fs, "text/plain", null) as DocumentEntry; 

此代码给出错误。我如何编辑公共文档。

我只有共享文档链接,我需要更新它。

4

2 回答 2

1

如果您知道文档名称或资源 ID,并且该文档与您共享,并且您具有正确的读/写访问权限 (ACL),那么更新资源应该没有任何问题。

通常使用 Google Documents API 更新文档是这样的:

  1. 获取文档的 DocumentEntry。您可以构造一个 DocumentQuery 以根据某些搜索参数查找目标文档。请参阅此处的文档: Google Documents List API 3.0

  2. 从 DocumentEntry 对象获取下载 URL 并将文档下载到您的 PC。如果您对修改原始内容不感兴趣并且只想上传并用您在本地制作的内容覆盖内容,则下载是可选的。

  3. 编辑文档并将其更新(上传)到 Google 文档。 更新文档。 具体来说,请查看“使用可恢复协议更新文档或文件内容”部分。现在将任何内容上传到 Docs 时必须使用 ResumableUploader。

编辑添加:尝试使用以下方法从公共链接获取 DocumentEntry:

// 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); 
于 2013-01-28T09:23:59.337 回答
0
    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());

这段代码很好用。谢谢你的帮助。

于 2013-01-29T08:47:00.707 回答