SPSiteDataQuery Samples for WSS v3

Search

Accessible SharePoint WebSites
Download ARF

SPSiteDataQuery Samples for WSS v3

http://blog.thekid.me.uk

Related Posts...

WSS Field Names for Lists & Document Libraries, Test your SPSiteDataQuery parameters using Snippet Compiler, Problems with WSS columns & internal field names, Specifying the Internal Name for WSS Columns, XML results using SPSiteDataQuery in SharePoint

I have been playing with the SPSiteDataQuery a fair bit recently and thought it would be interesting to post some of the results.

When using the SPSiteDataQuery to perform a search there are four main properties you are going to set which determine the results you will get. If you have seen my previous post (XML results using SPSiteDataQuery in SharePoint) you will have seen that they are Lists, Query, Webs and ViewFields.

If you read nothing else then remember this...If you make a mistake in the Webs or Lists properties, invalid XML or invalid attributes, the SPSiteDataQuery will fall back to it's default behavior and will not throw an error!! Knowing this can save a lot of time...ensure your properties are correctly formatted.

So, assuming the basic setup is

SPSiteDataQuery q = new SPSiteDataQuery();
q.Lists = "<Lists BaseType='1'/>";
q.Query = "<Where><Gt><FieldRef Name='ID' /><Value Type='Number'>0</Value></Gt></Where>";
q.Webs = "<Webs Scope='SiteCollection' />";
q.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='ID' />"';
q.RowLimit = 10;

Here are the changes you can make to achieve different result sets and tips as to why the query could be failing.

 

The Webs Property

There are basically three different values for this...


"<Webs Scope='SiteCollection' />" This will search the entire site collection no matter which web you use to execute the query.
"<Webs Scope='Recursive' />" This will search the web on which you execute the query and recurse through any child webs.

"" If you leave it blank then it will only search the web on which you execute the query. No child webs will be queried. This is important as I have read on several other sites that this is not possible with SPSiteDataQuery, but it is!!

I would also point out that that if you get anything wrong with this property SharePoint will not throw an error, it will just default to the blank behavior...It will only search the web on which you executed the query. This is an important point as "<Webs scope='Recursive' />"  or "<Webs Scope='recursive' />" (small 's' in Scope and small 'r' in recursive) look OK but are actually invalid and the query will default to only the current web.

 

The Lists Property

This defines what type of document libraries and lists WSS will search for your items. You can specify the exact type of list, the base type or even specific lists. Examples of the Lists property are...

"<Lists BaseType='1'/>" As above, this will search all lists which are based on a 'Document Library. This is useful if you only want to find documents. Other values for BaseType include...

0 - Generic list - This will search all lists and not document libraries.
1 - Document Library
3 - Discussion Forum
4 - Vote or Survey
5 - Issues list

(no, I don't know what happened to number 2!!)

I should also point out that the default is to search BaseType = '0' , and so if you do not set or make a mistake in the XML only lists will be searched.

"<Lists ServerTemplate='850'/>" This will limit the search to only a particular list template (850 is the Pages template in a publishing site). The number is fairly random and is defined in the list definition. I haven't needed to look at them as yet so I don't know a better way than looking in the definitions in the FEATURES folder for SharePoint. If you make a mistake with this property it will revert to the default.

Another options is Hidden, which determines if hidden lists or document libraries are searched. This an additional attribute and would be used like this...

"<Lists ServerTemplate='850' Hidden='TRUE'/>"

The MaxListLimit attribute specifies the total number of lists to search. You will receive an exception if the query exceeds the MaxListLimit. The default amount is 1000 and by setting this to 0 you can search everything. So the following would only search the first 50 lists...

"<Lists BaseType='1' MaxListsLimit='50'/>"

Another thing you can do with the Lists property is to query specific lists. This can be done by specifying the Guid of the list you want to search. An example would be...

"<Lists><List ID="129AB4CAE-12EF-9871-DE45-F34A180D3EAB5"/></Lists>"

You would obviously need to know the Guid of the lists you wish to query before creating this property.

 

The ViewFields property

The ViewFields property specifies the fields (columns), that will be returned in the query. This is very similar to SQL and you should ensure that you specify any fields that you may wish to use in you Where or OrderBy part of the query.

Things to point out here is that that you can specify the ID(Guid) of the property or the name of the property...this is the Internal Name, not the name you may see in the UI. For example the standard publishing field "Image Caption" would become "PublishingImageCaption" as that is it's internal name.

So, to add the "Image Caption" filed to the results we would need...

"<FieldRef Name='Title' /><FieldRef Name='ID' /><FieldRef Name='PublishingImageCaption' />"

Another thing to remember is that not all lists or documents libraries contain the same fields. If you are not worried about a particular field and want the item returned whether the field (column) exists or not the you can set Nullable to true. So if we have some items which may not have an 'Image Caption' column then we could use...

"<FieldRef Name='Title' /><FieldRef Name='ID' /><FieldRef Name='PublishingImageCaption' Nullable='TRUE'/>"

and this would still find those items without an 'Image Caption' column (field).

 

The Query Property

This property will allow you to bot limit and order you results. You can do both or just one, but it is similar to SQL in what you can do. There is a lot to this, but I will give a couple of samples...

Querying by date...

string sLastWeek = SPUtility.CreateISO8601DateTimeFromSystemDateTime(DateTime.Today.AddDays(-1));
q.Query = "<Where><Gt><FieldRef Name='Created'><Value Type='DateTime'>" + sLastWeek + "</Value></Gt></Where>";

This will find items created within the last week. The <Gt> denotes 'Greater Than', you could also use <Gte>, <Lt> or <Eq>. These can be combined to create more complex queries.

q.Query = "<OrderBy><FieldRef Name='Title' Ascending='FALSE'></OrderBy>";

This will order the items descending by the title (Z-A).

q.Query = "<Where><Gt><FieldRef Name='Created'><Value Type='DateTime'>" + sLastWeek + "</Value></Gt></Where><OrderBy><FieldRef Name='Title' Ascending='FALSE'></OrderBy>";

This is a combination of the above...items created in the last week ordered Z-A.

Finally, make sure you set the RowLimit property...you may not get any results otherwise!!

More information can be found on MSDN.

Posted by Vincent Rothwell on Tuesday, 27 Feb 2007 16:58  - 44 Comments
Orininally printed from http://thekid.me.uk - Copyright Vincent Rothwell 2007
 

Comments

Sunday, 27 Jul 2008 10:36 by Vince
lonsharim, As far as I know not by default. You could however configure your query with some additional WHERE clauses that check the URL of the items. This clause could be generated from the SiteDirectory. eg. <Where><BeginsWith><FieldRef Name="FileRef"/><Value>http://yoursite/A</Value></BeginsWith></Where>. This is off the top of my head but hopefully you get the idea. You could also use the Office Search & managed properties (if you don't need real time results). Vince

Sunday, 27 Jul 2008 10:36 by lonsharim
One of things I need to to do is exclude sub sites from the search that dont belong to a category (based on the Site Directory) I am searching within. So if I have Site A,B,C,D,E within my site collection A,C,E could belong to "International" and B,D could belong to "Local" in the Site Directory. Is it possible to use the SPDataQuery to query lists from only A,C,E

Sunday, 27 Jul 2008 10:36 by bobby
ea9K3f Hi! Nice site! Where is a add to favorite button& ;) http://www.mysite.com

Sunday, 27 Jul 2008 10:36 by Keivan
Very informative and detailed. Thanks! I was wondering if there was a way to query for all lists by List Title.

Sunday, 27 Jul 2008 10:36 by Kalyan Guin
Hi, I have created a console application using the SPSiteDataQuery. Although it is not giving any error but it is not returning any value also. Any suggestion on this would be great for me. --------------------------------------------------------------------------- using System; using System.Data; using Microsoft.SharePoint; namespace SPSiteDataQueryDemo { class Program { static void Main(string[] args) { Program app = new Program(); app.RunQuery(); } private void RunQuery() { try { SPSiteDataQuery q = new SPSiteDataQuery(); q.Lists = "<Lists><List ID='7cdbdedd-7935-414a-9b12-ddd58dbc19cf'/></Lists>"; q.Query = "<Where><Eq>" + "<FieldRef Name='Unit_x0020_Name'/>" + "<Value Type='Choice'>KDP</Value>" + "</Eq></Where>"; q.Webs = "<Webs Scope='Recursive'/>"; q.ViewFields = "<FieldRef Name='Test Case Type'/>"; DataTable dt = null; using (SPWeb w = SPContext.Current.Site.OpenWeb("http://KOLHODEV02:4444/KDP")) { dt = w.GetSiteData(q); } foreach (DataRow dr in dt.Rows) { Console.WriteLine(dr); } Console.Read(); } catch (Exception ex) { } } } } ------------------------------------------------------------------------

Sunday, 27 Jul 2008 10:36 by Kalyan Guin
Hi, I have created a console application using the SPSiteDataQuery. Although it is not giving any error but it is not returning any value also. Any suggestion on this would be great for me. --------------------------------------------------------------------------- using System; using System.Data; using Microsoft.SharePoint; namespace SPSiteDataQueryDemo { class Program { static void Main(string[] args) { Program app = new Program(); app.RunQuery(); } private void RunQuery() { try { SPSiteDataQuery q = new SPSiteDataQuery(); q.Lists = "<Lists><List ID='7cdbdedd-7935-414a-9b12-ddd58dbc19cf'/></Lists>"; q.Query = "<Where><Eq>" + "<FieldRef Name='Unit_x0020_Name'/>" + "<Value Type='Choice'>KDP</Value>" + "</Eq></Where>"; q.Webs = "<Webs Scope='Recursive'/>"; q.ViewFields = "<FieldRef Name='Test Case Type'/>"; DataTable dt = null; using (SPWeb w = SPContext.Current.Site.OpenWeb("http://KOLHODEV02:4444/KDP")) { dt = w.GetSiteData(q); } foreach (DataRow dr in dt.Rows) { Console.WriteLine(dr); } Console.Read(); } catch (Exception ex) { } } } } ------------------------------------------------------------------------

Sunday, 27 Jul 2008 10:36 by Vince
Kalyan, A few things you could try... 1. The FieldRef 'Test Case Type' looks wrong...use the internal name or add Nullable='TRUE' 2. Add Unit_x0020_Name to your ViewFields 3. Change your query from Type='Choice' to Type='Text' 4. Try q.Webs = "" (You are query a specific list, so you shouldn't need recursive). 5. Ensure the List is in the SPWeb you are querying. --Vince

Sunday, 27 Jul 2008 10:36 by Stephen Wilder
Thanks a lot for this post Vincent - I have spent hours Googling for this solution! Now I have found it I can prove DVWP really is the Swiss Army knife of SharePoint.

Sunday, 27 Jul 2008 10:36 by Nick
Hi Vince, how're things? Have you ever tried retrieving Wiki Pages using SPSiteDataQuery? Can't find any info to say it's not possible, yet so far every combination of parameters I've tried has come up blank. I know it's recursing into the Wiki Site as the query is returning documents from that sub-site's Documents list, but pages (ContentType = 'Wiki Page') seem to get ignored. I'm specifying the lists explicitly by ID and it's definitely got the Wiki Pages list in the query, have tried it with or without specifying explicit ContentType values. We're working round it for now by adding an extra Content Query web part, but we really wanted Pages, Wiki Pages and Documents all in the one hit, so just wondering if you'd come across it at all. Cheers

Sunday, 27 Jul 2008 10:36 by Vince
Nick, I see no reason why it shouldn't work, but I have never used it with Wiki pages. In general when you don't see any results for a particular content type it is because you have a ViewField specified (or a field in the query) which does not exist in the ContentType you expect to find. I would suggest either cutting the number of ViewFields (just to ID) to ensure you get some results or adding Nullable='TRUE' to the ones you have in your query. Remember the Internal name for a viewfield can change from list to list...http://blog.thekid.me.uk/archive/2007/03/12/wss-columns-specify-internal-name.aspx Vince

Sunday, 27 Jul 2008 10:36 by Hugo
How can sorting by a datetime column be accomplished? I keep getting the error: "Expression type datetime is invalid for COLLATE clause." This is my query: <Where><And> <Eq> <FieldRef Name='ContentType' /> <Value Type='Choice'>ExperienceReviewComponent</Value></Eq> <Eq> <FieldRef Name='UserID' /> <Value Type='Text'>I70787</Value></Eq></And></Where><OrderBy><FieldRef Name='ModifiedDateTime' Type='DateTime' Ascending='TRUE' Nullable='TRUE'/></OrderBy> Thanks

Sunday, 27 Jul 2008 10:36 by Vince
Hugo, I can see your comment properly...even if it's not rendered properly here!! (I'll fix that) From your query, my guess is that you do not need the Nullable='TRUE' on your OrderBy clause (not sure that's valid!). I would also ensure that the ModifiedDateTime field is included in your ViewFields...possibly it's not required...probably best to include it.

Sunday, 27 Jul 2008 10:36 by theGinna
Hi Vince, Thanks for that article, quite informative and a great boost to my SharePoint knowledge. I was wondering if you can help me? I would like to know if there is a way for the SPSiteDataQuery call to return other versions of content/list items? For example, I have turned on versioning and approval for a FAQ list I have created. I have 2 versions of a FAQ item, 1.0 is approved and 2.0 is currently pending. If I call SPSiteDataQuery to return my FAQ data, I can see the 2.0 version of the list item. In a real world example I would want the Live site to display version 1.0 and the DEV/Test/intranet site to display version 2.0, if you know what I mean? Can this be done? I am using WSS 3.0 rather than MOSS and I am using SPSiteDataQuery in a WebPart to render the FAQs to a SharePoint web page. Thanks!

Sunday, 27 Jul 2008 10:36 by Vincent
Hi, The SPSiteDataQuery should return the latest version you have permission to see. So on an annonymous site the user does not have permission to the pending version and so will see the last approved version. You will see the pending version if you are logged in I use that on this blog (which is running on WSS) when adding new functionality. I can change the .master page, but the changes are not available to annonymous users until I approve the file. This allows me to make changes and see then whilst logged in and approve them when they are correct.

Sunday, 27 Jul 2008 10:36 by Saurabh
Hi I am trying to use Multiple Lists in SPSiteDataQuery and each list has SiteColumn Name "ID" (which is by default in SPList). Now i want to make query and create Filter on "ID" field.........how does SPSiteDataQuery knows "ID" of which List i m using....?? SPSiteDataQuery dQuery = new SPSiteDataQuery(); dQuery.Lists = "<ListID=" + List1.ID + "/><ListID=" + List2.ID + "/><ListID=" + List3.ID + "/><ListID=" + List4.ID + "/><ListID=" + List5.ID + "/>"; dQuery.Query = @"<Where>" + "<Gt>" + "<FieldRef Name=\"ID\"/>" + "<Value Type=\"Counter\">0</Value>" + "</Gt>" + "</Where>"; how does it know the "ID" m using is of List1,List2,List3,List4 or List5.....??? plz tell me where m wrong...... Thanx n Regards

Sunday, 27 Jul 2008 10:36 by
Hi I am trying to use Multiple Lists in SPSiteDataQuery and each list has SiteColumn Name "ID" (which is by default in SPList). Now i want to make query and create Filter on "ID" field.........how does SPSiteDataQuery knows "ID" of which List i m using....?? I have 5 Lists List1,List2,List3,List4,List5 List1=SPContext.Current.Site.RootWeb.Lists["List1"]; //It is at the TopLevel Website List2=SPContext.Current.Web.Lists["List2"];//It is at Current Level List3=SPContext.Current.Web.Lists["List3"];//It is at Current Level List4=SPContext.Current.Web.Lists["List4"];//It is at Current Level List5=SPContext.Current.Web.Lists["List5"];//It is at Current Level SPSiteDataQuery dQuery = new SPSiteDataQuery(); dQuery.Lists = "<ListID=" + List1.ID + "/><ListID=" + List2.ID + "/><ListID=" + List3.ID + "/><ListID=" + List4.ID + "/><ListID=" + List5.ID + "/>"; dQuery.Query = @"<Where>" + "<Gt>" + "<FieldRef Name='ID'/>" + "<Value Type=\"Counter\">0</Value>" + "</Gt>" + "</Where>"; dQuery.ViewFields = "<FieldRef Name='ListDescription' /><FieldRef Name='ListTitle' />"; how does it know the "ID" m using is of List1,List2,List3,List4 or List5.....??? plz tell me where m wrong......

Sunday, 27 Jul 2008 10:37 by Dan H
An error in your very handy article... Is is MaxListLimit or MaxListsLimit - note the S ;-) !!! Thanks, Dan H

Sunday, 27 Jul 2008 10:37 by Rohit Saigal
Really good and informative. Microsoft should be the one giving out such documentation for developers. Keep the good work going !! Thanx, Rohit

Friday, 1 Aug 2008 02:30 by Vishwanath
I was searching for some of the SPSiteDataQuery examples and found your interesting blog, It is really nice and informative but i have two issues which i am not able to solve i) if i specify "<FieldRef Name=\"First Name\"/>" in where condition i dont find the result but if choose the title then i get the results. The first name is custom column,i am not able to search on any other custon column which i have created. ii) I have requirement where I need to Search for all the List in my particular site collection so I changed the ListBasetype to 0 but I also want to search for all the fieldref values i.e. in the given example it is Title, I wont be able to specify the particular FieldRefName as there many custom columns created, to explain you more with e.g i should be able to search all my lists in the sitecollection with value of "vishwa" which is of text type and it should return me all the list which contain this particular value in any column may be in last name column or middle name column How can I achieve this using SPsiteDataQuery or any other methods? I would appreciate if you can suggest some solution. Waiting for your early response.

Thursday, 4 Sep 2008 05:28 by Mark Stokes
Vishwanath, You might find that your FieldRef is using the Display Name for your field and not the internal name. Since you have <FieldRef Name=\"First Name\" /> it is highly likely this is not the internal name, as the space will probably be replaced with _x0020_ giving you: <FieldRef Name=\"First_x0020_Name\" />

Sunday, 21 Sep 2008 03:53 by Roy Gilboa
Thanks Vincent, very useful information. I needed to filter according to a specific custom list and 'ServerTemplate' was one of the things I needed to figure out. Here is how I got it (perhaps there is a better way): XmlReader reader = XmlReader.Create(new StringReader(list.PropertiesXml)); reader.Read(); string serverTemplate = reader.GetAttribute("ServerTemplate"); reader.Close(); Hope this helps someone... Roy

Tuesday, 23 Sep 2008 05:59 by Roy Gilboa
Thanks Vincent, very useful information. I needed to filter according to a specific custom list and 'ServerTemplate' was one of the things I needed to figure out. Here is how I got it (perhaps there is a better way): XmlReader reader = XmlReader.Create(new StringReader(list.PropertiesXml)); reader.Read(); string serverTemplate = reader.GetAttribute("ServerTemplate"); reader.Close(); Hope this helps someone... Roy

Friday, 7 Nov 2008 03:46 by Yeison
Hi, I do a query with SPSiteDataQuery, but I dont get items from List where I dont have read permissions, is there any method to allow it? I'm trying with the following code but I dont get it: string andStart = string.Empty; string andEnd = string.Empty; string filters = GetFilters(out andStart, out andEnd); SPSiteDataQuery siteQuery = new SPSiteDataQuery(); siteQuery.Lists = GetLists(); siteQuery.ViewFields = GetViewFields(); siteQuery.Query = GetQuery(filters, andStart, andEnd); siteQuery.RowLimit = GetRowLimit(); siteQuery.Webs = GetWebs(); DataTable results = null; SPSecurity.RunWithElevatedPrivileges(delegate() { results = Web.GetSiteData(siteQuery); }); Thanks for some suggestion.

Thursday, 13 Nov 2008 02:36 by Quadboy
Seems that we have to be under administrator account to use the SPSiteDataQuery class ?

Wednesday, 26 Nov 2008 04:40 by Vince
Yeison, Quadboy, No you don't have to be Admin, that is standard SharePoint behaviour...if you can't read it it won't let you see it. If you want to list items that the user doesn't have access to then run your code using SPSecurity.RunWithElevatedPrivelges() --Vince

Wednesday, 17 Dec 2008 03:42 by Mark Stokes
Hey guys, I have been very happily using the SPSiteDataQuery for a while, however yesterday I cam across an interesting problem. I could not run the method SPWeb.GetSiteData() on a publishing site. I kept getting pushed to the Access Denied page. I was logged onto my dev box with a farm administrator account, who also had owner permissions on all Sites in the Collection that I was aggregating from. I could quite happily use a ContentByQuery Web Part to ennumerate the same content. In the end I have gone with the CrossListQueryInfo which appears to work. I am not sure if it's something to do with my environment or not, but would be interested to hear if anyone else has had similar problems? Mark

Wednesday, 4 Feb 2009 09:06 by Jari Ivanoff
Is there a way to get a max value from a sitecolumn? I.e. I have a bunch of documents with a manually entered number in a column called DocNr. I would like to have the larges number in that column so I can make that function automatic with a simple DocNr + 1 functionality. I have tried to find some C# examples of how to do this without results. Best regards Jari

Thursday, 19 Feb 2009 04:01 by David Brosch
Hi Vincent, great post about SiteDataQuery. During my quest for answers it has been quite helpful. Unfortunately I ran into an issue which keeps me busy now for almost a week. Maybe you have have a clue about it. I use a sitedataquery to query a couple of custom lists with fields based on a custom field type. The Field type derives from SPFieldLookup. I am querying the lists and get proper results until I use my field in the Viewfields. Then it returns nothing. If I set Nullabe="TRUE" I get results, but that field is returned empty, though it contains data. I can use this field in the Query statement and get properly filtered results. I simply cannot get the field back as part of the Viewfields. I have already tried to use the internal name, display name and id (guid) of the field, with now luck. Do you have any idea where to look? Thanks and best regards David

Wednesday, 18 Mar 2009 11:42 by Damien
Hi, I was trying to get a link of each item I retreive using SPSiteDataQuery. Here is how to do it: 1. add "<FieldRef Name=\"FileRef\" />" into your query's ViewFields 2. retreive the row["FileRef"] and apply this code to transform the ref to URL as follow: string [] slipFileRef = row["FileRef"].ToString().Split('#'); string fullUrl = "<a href=\"" + site.MakeFullUrl(slipFileRef[1].Remove(slipFileRef[1].LastIndexOf('/') + 1) + "DispForm.aspx?ID=" + slipFileRef[0].TrimEnd(';')) + "\">Test this link</a>"; cheers, Damien

Tuesday, 31 Mar 2009 03:11 by surya
Hi Vince, Great article. I was wondering though. How can we query one list and one doc lib simultaneously ? I tried creating the lists property as "<List ID=''><List ID=''>" but it fails to get the items of document libraries. Any suggestions ? Thanks

Wednesday, 22 Apr 2009 08:53 by Raja
Just wanted to let you know..below post looks very similar to yours..word for word :) http://littletalk.wordpress.com/2008/04/21/spsitedataquery-samples-for-wss-v3/

Tuesday, 9 Jun 2009 12:43 by Ananth
Thanks a lot! The info provided in the blog was helpful to know more about SPSiteDataQuery! Good Luck! - Ananth

Friday, 26 Jun 2009 04:49 by Shridha
BaseTypes to be used are as follows: //DiscussionBoard = 3, //DocumentLibrary = 1, //GenericList = 0, //Issue = 5, //Survey = 4, //UnspecifiedBaseType = -1, //Unused = 2

Saturday, 27 Jun 2009 10:36 by Kreidecky
Hi, very nice and helpfull article! I was wondering, is there an option to do a DISTINCT search with SPSiteDataQuery? Thanks!

Tuesday, 30 Jun 2009 02:52 by
Great article! I was wondering the same thing as Keivan, is it possible to filter lists by title? For example <Lists><List Title='test' /></Lists> (which does not work). Thanks!

Friday, 7 Aug 2009 11:42 by Nehru
Really good article but unfortunately its not working for me when I tried to find out data by the query with servertemplate every time it returns me the same data irrelevant of the servertemplate Please advice here is my code SPSiteDataQuery q = new SPSiteDataQuery(); //q.Lists = string.Format("<Lists BaseType='{0}' MaxListsLimit='{1}' ServerTemplate='{2}'/>", baseType.ToString(), this.MaxLists.ToString(), serverTemplate.ToString()); q.Lists = string.Format("< ServerTemplate=\"{0}\" />", serverTemplate.ToString()); switch (this.QueryScope) { case QueryScopeEnum.Recursive: q.Webs = "<Webs Scope=\"Recursive\"/>"; break; case QueryScopeEnum.Site: q.Webs = ""; break; case QueryScopeEnum.SiteCollection: q.Webs = "<Webs Scope=\"SiteCollection\"/>"; break; } q.ViewFields = "<FieldRef Name=\"Title\"/><FieldRef Name=\"ID\" /><FieldRef Name=\"Modified\" /><FieldRef Name=\"Editor\" Nullable=\"TRUE\"/>"; //q.ViewFields = "<FieldRef Name='Title' /><FieldRef Name='ID' /><FieldRef Name='Modified' /><FieldRef Name='Editor' Nullable='TRUE'/>"; q.Query = "<OrderBy><FieldRef Name=\"Modified\" /></OrderBy>"; DataTable tbl = web.GetSiteData(q); return tbl;

Wednesday, 30 Sep 2009 10:18 by Rob Volk
FYI - The values for <Lists ServerTemplate="nn" /> are found in the enumeration Microsoft.SharePoint.SPListTemplateType

Wednesday, 30 Sep 2009 10:57 by Rob Volk
FYI - The values for <Lists ServerTemplate="nn" /> are found in the enumeration Microsoft.SharePoint.SPListTemplateType

Friday, 6 Nov 2009 01:50 by Ben
I just wanted to throw a tid bit out there just FYI. This is to help people get a value to a item field value. I was trying to find how to get the Name from a SPListItem. After much search I finally found it buried in a debug feature on the watch list in Visual Studio. If you are looking for a value to set the 'Name' property in <FieldRef Name='{Something Here}' />. If you look at the XML under the {List Name}.Items.XML, then you can find the value to set the 'Name' property to. Note: You want to get the "s:AttributeType name" not "rs:name" out of the XML element. Example: <s:AttributeType name="ows_Author" rs:name="Created By" rs:number="5"> <s:datatype dt:type="string" dt:lookup="true" dt:maxLength="512" /> Hope that makes since and can help someone out.

Monday, 4 Jan 2010 03:24 by Jerry
I am trying to use your method on a CKS:EBE site to return blog Posts and Comments together, but for some reason I cannot seem to get to the comment items. I've tried explictly using list guids, but even the basic "<Lists BaseType='0'/>" should work -- in fact, that should also return rows for my 3 Categories items, yet I ONLY seem to get Post items. Any ideas? Thanks!

Monday, 4 Jan 2010 03:39 by Jerry
disregard my question... I just saw that Comments do not have a "PublishedDate", which was referenced in my <OrderBy>. duh. Thanks again for the great article!

Thursday, 6 May 2010 10:56 by Thrilled2Bits
Interesting page, thank you all for your contribution. I have similar probs to that mentioned above. I am using CAML to retrieve the all items based on aparticular content type - success. When I narrow the search based on one of the custom column it does not return any - failed. After much investigating and comparing with DocLib that does fetch results I have found and successfully replicated the problem. However I am unable to fix this even with RunWithElevatedPriv... Replication: Versioning Settings - Set Doc Version History to 'Create Major Versions' then for Draft Item Security select 'Any user who can read items '. The CAML will search this Doc Lib if used with content type or any other system fields but when conditioned with a custom column it will not work. However setting the Doc Version History to 'Create Major and Minor' and Draft Item Security to 'Only users who can edit items' then I get back the results and using any number of field combinations. Can anyone HELP! Is this a bug in SP, has it been logged, can't seem to find a resolution to it....

Wednesday, 9 Jun 2010 11:27 by Gopalakrishnan
Hi, I want to use SPSiteDataQuery object to search for items in a list named "Dockets" across sub-sites in a site collection. Each sub-site has a list named "Dockets". How can I give the filter query for the same? Also, is it possible to filter by Content Type(s)?

Thursday, 10 Jun 2010 01:34 by Harsh
Hi Vincet, I have a query, I want to display all fields of two lists and no one field is common into these two lists, suppose List A has fields a, b, c and List B has fields d,e,f, I has used query.Lists = <Lists><List ID = 'asdasds89900asd'><List><List ID='xckdsfd89sdkfd9nsad9'>, query.ViewFields=<FieldRef Name='a'><FieldRef Name='b'><FieldRef Name='d'><FieldRef Name='e'> and so on. I have not used where clause, I want to display all six fields of two lists. Is it possible?



Url

Email

Comments