Kangkan
Kangkan

Reputation: 15571

How to get all the documents in a folder in Google Docs

I can get all the documents in Google Docs using

    public DocumentsFeed GetDocs()
    {
        DocumentsListQuery query = new DocumentsListQuery();
        DocumentsFeed feed = service.Query(query);
        return feed;
    }

But how can I get the documents in a particular folder? I wan to discover the list of folders and then populate the folders in a tree view. On selection of a folder, I shall like to get the documents in that folder.

To get the folder, I am using

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

    }

For the service, I am using private DocumentsService service;

Can somebody help?

Upvotes: 2

Views: 2827

Answers (2)

Nikola Sivkov
Nikola Sivkov

Reputation: 2852

Here's how :

instead of typing the name of the folder , use the resourceID of the folder query = new FolderQuery(FolderEntry.ResourceId);

But first you need to get ALL documents in the root and enable showing folders : query.ShowFolders = true; , that's how you get the resourceId's of the docs in the root and folders!

Hope this helps !

Upvotes: 0

LMW-HH
LMW-HH

Reputation: 1193

Another guy using the API has described how he does it:

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);
    }
}

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

Upvotes: 1

Related Questions