Microsoft Content Management Server - Looping through all resources in the resource gallery

This is Interesting: Free IT Magazines  
Home > Archive > Microsoft Content Management Server > February 2006 > Looping through all resources in the resource gallery





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Looping through all resources in the resource gallery
Duffler

2006-02-26, 10:46 am

Hi all, i'm compiling a report (in csv forat) of all resources in all
of our resource galleries, however i've run into some problems. Our
resource gallery is in the following format:

Resources/SiteName/Docs: e.g. Resources/CaseStudies/Docs
Resources/SiteName/Pdf e.g. Resources/CaseStudies/Pdf
Resources/SiteName/other e.g. Resources/CaseStudies/other

We have 33 parent containers in the resource gallery with the outlined
sub containers (pdf, docs and other containing various pdf, word doc
and associated other file formats. Now when i run the code below it
will only give me the parent containers resources i.e and not the all
resources residing in the sub-containers.

Resources/SiteName/ some resources e.g. jpegs etc

Do i need to inlcude a loop within the two loops i have already to
display the resources in the sub galleries i.e. pdf, docs and other.
If so can someone advise on how i do this..please see my paltry code
below!

ResourceGallery rsg = apc.Searches.GetByPath("/Resources/") as
ResourceGallery;
ResourceGalleryCollection MyCollection = rsg.ResourceGalleries;
MyCollection.SortByName();
foreach (ResourceGallery rst in MyCollection)
{

strPageOutput = "";
strPageOutput = strPageOutput + rst.Name;
strPageOutput = strPageOutput + ",";
strPageOutput = strPageOutput + rst.Parent;
strPageOutput = strPageOutput + ",";
strPageOutput = strPageOutput +
rst.LastModifiedBy.ToString().Replace("WinNT://", "");
strPageOutput = strPageOutput + ",";

foreach (Resource rs in rst.Resources)
{
strPageOutput = strPageOutput + rs.Url;
}
sw.WriteLine(strPageOutput);
}

Thanks in advance.
John.

Hadi

2006-02-26, 10:46 am

Hi Duffler,
Your code only displays the resource galleries and does not take care to
loop through the resource gallery itself and scan for the resource gallery
items.
I did something similar a few weeks back by writing the following function.
Feel free to modify to suit your needs. Simply call the function by supplying
the resource gallery starting path which I set in the web.config file and
specified using the following line:
Dim rglGallery As ResourceGallery =
CmsHttpContext.Current.Searches.GetByPath(System.Configuration.ConfigurationSettings.AppSettings.Item("ResourceLocation"))


Heres the function itself:

Private Sub getChildren(ByVal rootGallery As ResourceGallery)
Dim rgi As ResourceGalleryItem
Dim rg As ResourceGallery
Dim rsc As Resource

For Each rg In rootGallery.ResourceGalleries
globalGalleryCount = globalGalleryCount + 1
Response.Write("<BR>" & rg.Path.ToString)
rg.Resources.SortByDisplayPath()
For Each rsc In rg.Resources
globalResourceCount = globalResourceCount + 1
Response.Write("<BR>" & rsc.Path.ToString & "<BR><a href=" &
rsc.Url & " target='new'>" & rsc.Url & "</a>")
Call trackFileTypes(rsc.Path.ToString)
Next rsc
Call getChildren(rg)
Next rg
End Sub

Hope it helps.
Hadi M


"Duffler" wrote:

> Hi all, i'm compiling a report (in csv forat) of all resources in all
> of our resource galleries, however i've run into some problems. Our
> resource gallery is in the following format:
>
> Resources/SiteName/Docs: e.g. Resources/CaseStudies/Docs
> Resources/SiteName/Pdf e.g. Resources/CaseStudies/Pdf
> Resources/SiteName/other e.g. Resources/CaseStudies/other
>
> We have 33 parent containers in the resource gallery with the outlined
> sub containers (pdf, docs and other containing various pdf, word doc
> and associated other file formats. Now when i run the code below it
> will only give me the parent containers resources i.e and not the all
> resources residing in the sub-containers.
>
> Resources/SiteName/ some resources e.g. jpegs etc
>
> Do i need to inlcude a loop within the two loops i have already to
> display the resources in the sub galleries i.e. pdf, docs and other.
> If so can someone advise on how i do this..please see my paltry code
> below!
>
> ResourceGallery rsg = apc.Searches.GetByPath("/Resources/") as
> ResourceGallery;
> ResourceGalleryCollection MyCollection = rsg.ResourceGalleries;
> MyCollection.SortByName();
> foreach (ResourceGallery rst in MyCollection)
> {
>
> strPageOutput = "";
> strPageOutput = strPageOutput + rst.Name;
> strPageOutput = strPageOutput + ",";
> strPageOutput = strPageOutput + rst.Parent;
> strPageOutput = strPageOutput + ",";
> strPageOutput = strPageOutput +
> rst.LastModifiedBy.ToString().Replace("WinNT://", "");
> strPageOutput = strPageOutput + ",";
>
> foreach (Resource rs in rst.Resources)
> {
> strPageOutput = strPageOutput + rs.Url;
> }
> sw.WriteLine(strPageOutput);
> }
>
> Thanks in advance.
> John.
>
>

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com