tags:

views:

158

answers:

1

Consider this SharePoint site hierarchy:

- Site Collection
 - Site1
     - Subsite1
         - AnotherSubsite1
             - Page1
             - Page2
         - AnotherSubsite2
     - Subsite2
         - Page3
         - Page4
 - Site2

You can assume that every Site in the above hierarchy has a default page.

If I place a CQWP on Site1's default page, can I instruct it to start getting data one level below where it was placed? i.e. ignore the page/site it's currently on, so that it returns:

     - Subsite1
         - AnotherSubsite1
             - Page1
             - Page2
         - AnotherSubsite2
     - Subsite2
         - Page3
         - Page4

Thank you

+2  A: 

I would extend the CQWP and then hook up my own ProcessDataDelegate to remove the data that's not required. For example:

protected override void OnInit(EventArgs e)
{
    this.ProcessDataDelegate += ProcessItems;
}

public DataTable ProcessItems(DataTable data)
{
    // Query the DataTable and remove unnecessary information
}

The WebId column in data is the GUID for the SPWeb object of each returned item. Look up SPWeb.ID of the sites you no longer want and then remove these rows. Note that the GUIDs in the WebId column are upper-case and in "D" format as described in Guid.ToString().

Remember to use AcceptChanges() at the end to ensure the DataTable is updated.

Alex Angas
That's an interesting approach, I could easily get a reference to the current site and exclude it
George Durzi
A quick look with Reflector shows that the CQWP isn't designed to support multiple URLs. I think going down that road would be long and painful.
Alex Angas
Gotcha, your approach for using the GUID of the SPWeb object would be much cleaner
George Durzi