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:
<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>
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.
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.
Paul:
You were doing the right thing putting the references into the Viewfields section. I’ve added an example above.
M.
Another gem!
Thanks, Nick. This one’s laid fallow for a long time. Just tweeted it into the light of day again.
M.
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?
David:
Make sure that you have each property explicitly in the section.
M.
Each property (Title and Url) is specified in the CAML selectcommand.
gives the title
is empty (as is SiteUrl)
David
David:
Hmm. Not sure that I’ve used the URL property. You could also get at it by using ddwrt:UrlDirName on @FileRef. Check my article on EndUserSharePoint. com for some details on this.
M.
It stripped out my xsl
<xsl:value-of select="@ProjectProperty.Title" /> – gives the title
<xsl:value-of select="@ProjectProperty.Url" /> – is empty
Can these properties also be used in the where clause? I tried but I can’t seem to get it working.
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.
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?
Jasper:
What Web Service are you calling? Lists.asmx? If you’re using the Web Service, can’t you just filter in your Silverlight code?
M.
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.
Got it. I was trying the CAML in a DVWP, so the behavior/effect there might be totally different. So you’re talking about the SiteData Web Service?
M.
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.
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.
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.
You might want to look at what other filter options you have. For instance, if you could filter on WebFullUrl or RootFolder. Since you’re working in code, you don’t really need the CAML properties.
M.
I do, SPSiteDataQuery requires a CAML XML query for the ‘where’ parameter. I have the feeling you don’t know SPSiteDataQuery? :)
http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spsitedataquery.aspx
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 \
\
\
\
\
\
Trygve:
I’m not sure of your question. Which Webs operation are you trying to use?
M.
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
Shiri:
It’s a little difficult to know what to recommend without seeing your XSL. I do think what you want to do is possible.
M.
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
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?