-4

Using Tridion Core Service how can we get existing folders of a particular publication. I am using SessionAwareCoreService2010Client class to create folders but could not locate in above class a proper method in core service to fetch list of all existing folders. Please answer with sample code.

Any help would be appreciated.

d k
  • 493
  • 2
  • 6
  • 21

2 Answers2

16

I would prefer to give you something to think about than some sample code that gets your job done (giving a man a fish and all that).

First - You say you're using SessionAwareCoreService2010Client hopefully because you're on Tridion 2011 GA instead of SP1. Otherwise I would certainly recommend using the pre-compiled client and the SessionAwareCoreServiceClient.

Now you say you want all folders. Do you want ALL folders in a publication in one call, or do you want to "walk" the hierarchy recursively?

All Organizational Items support a GetList call. With the CoreService this is achieved by using a client.GetListXml(subjectId, subjectRelatedFilter) call. If you only want folders, then you would start by creating a OrganizationalItemItemsFilterData object, and specifying that you want only objects of type Folder in the filter.ItemTypes array (along the lines of filter.ItemTypes = new[]{ItemType.Folder};

Now you can implement a method that would recursively call itself for every object returned by the client.GetList call and read whatever properties you need from the objects.

If you really need sample code, then I would recommend googling for it.

Community
  • 1
  • 1
Nuno Linhares
  • 10,214
  • 1
  • 22
  • 42
10

I can't test it at the moment, but it will be something like this:

var rootFolderUri = "tcm:1-1-2";
var filter = new OrganizationalItemItemsFilterData();
filter.ItemTypes = new[] { ItemType.Folder };
filter.Recursive = true;

var listXml = client.GetListXml(rootFolderUri, filter);

foreach (var itemElement in listXml.Descendants())
{
    ...
}
Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807