Project and List Properties Available from CAML

When you are building a DVWP in SharePoint, there are some project (Web site) and list properties that are available to you directly from CAML that aren’t well-documented, which you can use if you request them directly.  For instance, if you add the following to your CAML <ListProperty Name=”Title” /><ProjectProperty Name=”Title” />, the titles of the project and list are available to you:

<xsl:value-of select=”@ListProperty.Title” />
<xsl:value-of select=”@ProjectProperty.Title” />

These properties are especially useful when you build CrossList DVWPs in order to build up links to items and to display information about them on the page.

Here’s an actual example from a project I worked on:

&lt;View&gt;&lt;Webs Scope="SiteCollection"&gt;&lt;/Webs&gt;&lt;Lists ServerTemplate="104"&gt;&lt;/Lists&gt;&lt;Query/&gt;&lt;ViewFields&gt;&lt;ProjectProperty Name="Title"/&gt;&lt;FieldRef Name="ID"/&gt;&lt;FieldRef Name="Title"/&gt;&lt;FieldRef Name="Body"/&gt;&lt;FieldRef Name="FileDirRef"/&gt;&lt;FieldRef Name="Created"/&gt;&lt;FieldRef Name="Author"/&gt;&lt;FieldRef Name="Expires"/&gt;&lt;FieldRef Name="PermMask"/&gt;&lt;FieldRef Name="ShowOnRootPage"/&gt;&lt;/ViewFields&gt;&lt;/View&gt;

and again in “English”:

<View>
  <Webs Scope="SiteCollection"></Webs>
  <Lists ServerTemplate="104"></Lists>
  <Query/>
  <ViewFields>
    <ProjectProperty Name="Title"/>
    <FieldRef Name="ID"/>
    <FieldRef Name="Title"/>
    <FieldRef Name="Body"/>
    <FieldRef Name="FileDirRef"/>
    <FieldRef Name="Created"/>
    <FieldRef Name="Author"/>
    <FieldRef Name="Expires"/>
    <FieldRef Name="PermMask"/>
    <FieldRef Name="ShowOnRootPage"/>
  </ViewFields>
</View>

ProjectProperty.Property Value
A string that contains the name of a project property listed in the following table.

Name Value
BlogCategoryTitle Category of the current post item.
BlogPostTitle Title of the current post item.
Description Description of the current Web site.
RecycleBinEnabled 1 if the recycle bin is enabled; otherwise, 0.
SiteOwnerName User name of the owner for the current site collection.
SiteUrl Full URL of the current site collection.
Title Title of the current Web site.
Url Full URL of the current Web site.

See ProjectProperty.Property Property for the original MSDN article.

ListProperty.Property Value
A string that contains the name of a property listed in the following table.

Name Value
Created Date and time the list was created.
DefaultViewUrl Server-relative URL of the default list view.
Description Description of the list.
EnableSyndication true if RSS syndication is enabled for the list; otherwise, false.
ItemCount Number of items in the list.
LinkTitle Title linked to list.
MajorVersionLimit For a document library that uses version control with major versions only, maximum number of major versions allowed for items.
MajorWithMinorVersionsLimit For a document library that uses version control with both major and minor versions, maximum number of major versions allowed for items.
RelativeFolderPath Site-relative URL for the list.
Title Title of the list.
ViewSelector View selector with links to views for the list.

See ListProperty.Property Property for the original MSDN article.

29 Comments

  1. Can you post an example showing where in the CAML these additional references would go? I placed them in the ViewFields but it did not work there.

    Reply
  2. Hi Marc

    Great bit of info again! I have a DVWP that will display all documents from the site it sits on and below. It will show the ProjectProperty.Title but the ProjectProperty.Url is empty.

    Its CrossList and the Scope is Recursive. Any ideas?

    Reply
  3. It stripped out my xsl

    <xsl:value-of select="@ProjectProperty.Title" /> – gives the title
    <xsl:value-of select="@ProjectProperty.Url" /> – is empty

    Reply
    • Jasper:

      I just tried to use the ProjectProperty.Title in the Where clause, and I’m not having any luck, either. What are you trying to filter on? There’s probably another viable approach.

      M.

      Reply
  4. Hi Marc,

    I need to filter CAML results based on the site title. We’ve got several seperate sites setup for customers. I’ve created a Silverlight webpart which uses a webservice to get all unfinished tasks rolled up from all customer sites. I want to be able to filter those based on the customer name which is in the sitename. I can’t use the URL because that only contains the numeric customer code, not the name. Any ideas?

    Reply
      • Hi Marc,

        I’m using a custom build web service which executes a SPSiteDataQuery. Of course I can filter out data based on other things, but I want to make sure SPSiteDataQuery keeps performing. And when I first fetch a result set of say 1000 records whilst only needing 25 of those, that will affect performance. So I was hoping I could let SPSiteDataQuery do all the filtering, but I guess that might not be possible.

        Reply
          • Hi Marc,

            No, I’m not using an OOTB webservice. I use a custom webservice which I wrote and deployed as a solution. In this webservice, there is a method which uses the SPSiteDataQuery object to query all SharePoint lists on the site (and subsites) at once.

            Because there will be many subsites with many lists and even more items, I need the service to perform at its best.

            Reply
            • I think you’d be much better off using Webs.GetAllSubWebCollection, filtering those results for your customer name in the Title, and then going from there. That’s going to be far more efficient. You’ll never grab any items or lists from any sites which are outside your intended targets. I’m not sure that you need to write a custom Web Service at all.

              M.

              Reply
              • hi Marc,

                Thanks for the info. I need the custom web service for more things and since I like to have everything in one place I’ll leave it for now. The idea of using GetAllSubwebs is interesting, but I’m not quite sure about performance. Suppose I have 200 sites and 20 of those are retrieved after filtering. I´d then have to fire my query to each of those 20 sites and combine the results. I wonder if that´s truely faster then just querying everything and filtering afterwards. As I´ve read in a few blogs that SPSiteDataQuery is the fastest way to get data from sharepoint, that is when your CAML is ok of course.

                Reply
  5. I have the same question as Jasper. I’m using a basic client-side call to Webs.asmx. My SOAP envelope contains a CAML query much like a basic Lists.asmx query (Lists works Webs doesn’t).

    I’m assuming I just don’t have the proper CAML. Maybe FieldRef isn’t correct in this case?

    \
    \
    \
    \
    \
    \
    SomeText \
    \
    \
    \
    \
    \

    Reply
  6. Hi Marc,

    Thanks for this post!

    I’m using Dataview to display a list from a site in several sub sites. I want to filter them by the site title. I tried to use the ProjectProperty.Title but it’s showing the title of the original site and not the sub site, do you have any idea how to show the title of the current site?

    Thank you,
    Shiri

    Reply
      • Hi Mark,

        My XSL was as you wrote it in the blog – i added the to the SelectCommand and used it in the RowView template: .

        Anyhow, I used another method – I used GetAllSubWebCollection from webs.asmx, filtered it by URL and used the title.

        Of course your suggestion is easier, but I had to finish the task..

        Thank you,
        Shiri

        Reply
  7. Hi Mark,

    This works fine.. but for some reason when I have the column in my data view and hook up a filter web part to that column, it doesnt filter correctly. It keeps returning no results.

    Any idea why?

    Reply

Leave a Reply