如何获取Google文档中文件夹中的所有文档

时间:2012-02-06 07:33:50

标签: c# google-docs google-docs-api

我可以使用

获取Google文档中的所有文档
    public DocumentsFeed GetDocs()
    {
        DocumentsListQuery query = new DocumentsListQuery();
        DocumentsFeed feed = service.Query(query);
        return feed;
    }

但是如何在特定文件夹中获取文档?我想发现文件夹列表,然后在树视图中填充文件夹。在选择文件夹时,我想获取该文件夹中的文件。

要获取文件夹,我正在使用

    public DocumentsFeed GetFolders()
    {
        FolderQuery query = new FolderQuery("root"); //http://docs.google.com/feeds/documents/private/full
        DocumentsFeed feed = service.Query(query);
        return feed;

    }

对于服务,我使用的是private DocumentsService service;

有人可以帮忙吗?

2 个答案:

答案 0 :(得分:1)

另一个使用API​​的人描述了他是如何做到的:

var docService = new DocumentsService("company-app-version");
docService.setUserCredentials("username", "password");
using Google.GData.Client;
using Google.GData.Extensions;
using Google.GData.Documents;

// snipped method declaration etc

var docService = new DocumentsService("company-app-version");
docService.setUserCredentials("username", "password");

var folderList = docService.Query(new FolderQuery());
var fLinks = folderList.Entries.Select(e =>
new
{
    // note how to get the document Id of the folder
    Id = DocumentsListQuery.DocumentId(e.Id.AbsoluteUri),
    Name = e.Title.Text
});

foreach (var folder in fLinks)
{
    Console.WriteLine("Folder {0}", folder.Name);

    var fileList = docService.Query(
        new SpreadsheetQuery()
        {
            // setting the base address to the folder's URI restricts your results
            BaseAddress = DocumentsListQuery.folderBaseUri + folder.Id
        });

    foreach (var file in fileList.Entries)
    {
        Console.WriteLine(" - {0}", file.Title.Text);
    }
}

来源: http://jtnlex.com/blog/2010/06/09/google-docs-api-get-all-spreadsheetsdocs-in-a-folder/

答案 1 :(得分:0)

以下是:

而不是键入文件夹的名称,请使用文件夹resourceID的{​​{1}}

但首先你需要在root中获取所有文档并启用显示文件夹:query = new FolderQuery(FolderEntry.ResourceId);,这就是你如何获得root中文档的resourceId和 文件夹!

希望这有帮助!