SharePoint - multiple site libraries
Asked By sammy mc
08-Sep-10 09:29 PM
Hello all, I have to gather images from sites in a site collection by it's title name! any one know, the best practice!
Anand Malli replied to sammy mc
Hi Sammy,
to get records from the multiple sites across the site collection you need to use SPSiteDataQuery as SPQuery will work only for the single site..
you can use following code snippet to get your records from all the sites of the site collection...
SPWeb web = SPContext.Current.Web;
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;
DataTable dt = web.GetSiteData(query);
you can modify the query as per the filter you want to apply...
I hope u got ur solution...
sammy mc replied to Anand Malli
Thank you! It works with folders, sub-folders across the site collection. wondering I tried SPSiteDataQuery object oQuery
SPListItemCollection items = list.GetItems(oQuery); this does not work. any idea-
Anand Malli replied to sammy mc
Hi sammy,
you have tried following...
SPSiteDataQuery oQuery = new SPSiteDataQuery();
SPListItemCollection items = list.GetItems(oQuery);
It will not work as you tried to access it along with the SPList. which is not possible. to use with SPList.GetItems(oQuery) you need to have an object of SPQuery not of SPSiteDataQuery
the reason behind this is SPQuery will target to a single list where as SPSIteDataQuery will target to multiple lists.
I hope u got the difference between those two....
let me know if any other doubts u're having....:D

SPQuery and indexed field SharePoint Hello, How can we use the indexed fields in a spquery ? maybe we have to use another way to use the indexation ? can someone help me ? Thanks ! SharePoint Development Discussions SPSiteDataQuery (1) SPQuery (1) SPSite (1) SharePoint (1) AS far as I have been able to determin, the indexed fields are used by: 1. sharepoint enterprise search for keywords like "contains" 2. SPSiteDataQuery object in WSS that allows search throughout a site collection - - Ishai Sagi www.spstips.blogspot.com Developer tips for SharePoint how make a query which look on an indexed property propA and full- text ? Maybe
How to customize Sharepoint search using CAML Query Hi How to customize Sharepoint search using CAML Query . in my project we want to use content level search ((inside 05 / caml-query-lookup-field-by-id-not-by-value / hope this helsp you / . . . hi, SPQuery is the SharePoint object which is used to perform a query operation against SharePoint data.SPList.getItems(SPQuery) is the step, will return SPListItemCollection which satisfies the query.SPQuery has one data member ‘Query’, which need to set before passing SPQuery object to SPList. try this using (SPWeb web = SPContext.Current.Site.RootWeb) { SPList mylist = web
Join two SharePoint list in CAML Query Hi I have to join two lists in CAML Query to to do this. Thanks & Regards Sumit Kour Hi, To do a CAML query in a SharePoint list you can use the class SPQuery. Here's an example. Code: try { SPSite site = new SPSite("serveur_url"); SPWeb web = new site.OpenWeb(); SPList list = web.Lists["votre_liste"]; SPQuery query = new SPQuery(list.DefaultView); query.Query = " Une Valeur "; SPListItemCollection items = list.GetItems(query); foreach (SPListItem item in SPSite site = new SPSite("serveur_url"); SPWeb web = new site.OpenWeb(); SPList list = web.Lists["votre_liste"]; SPQuery query = new SPQuery(list.DefaultView); query.Query = " Une Valeur "; SPListItemCollection items = list.GetItems(query); foreach (SPListItem item in FieldRef Name = 'Champ2' / > . . . . "; Follow these libks- http: / / rmanimaran.wordpress.com / 2011 / 03 / 11 / new-in-sharepoint-2010-caml-query / http: / / praveenbattula.blogspot.com / 2010 / 02 / sharepoint-querying-caml-query-usage.html
ANOTHER SITE. . Hi, try this code to read the items of particular folder / / Create a SPQuery Object SPQuery curQry = new SPQuery(); curQry.Folder = folder; / / Write the query curQry.Query = "<Where> <Eq> <FieldRef Name = 'FIELD-NAME' / > <Value Eq> < / Where> " ; SPListItemCollection items = list.GetItems(curQry); Hope this will help you HI / / Create a SPQuery Object SPQuery curQry = new SPQuery(); curQry. Folder = folder; / / Write the query curQry.Query = "<Where> <Eq> <FieldRef Name = 'FIELD-NAME' / > <Value 1. This will return folders only. Next you can iterate the datatabel returned. public static DataTable GetListItemJustFolders() { string query = "< mylistitemrequest > < Query > < Where > < Eq > < FieldRef Name = \ "FSObjType \ " / > < Value Type = \ "Lookup \ "> 1< / Value Name = \ "ID \ " / > < FieldRef Name = \ "FileRef \ " / > < FieldRef Name = \ "ID \ " / > < FieldRef Name = \ "Title \ " / > < / ViewFields > < QueryOptions > < / QueryOptions > < / mylistitemrequest > "; DataTable dt = null; using(listservice.Lists listProxy = new listservice.Lists()) { listProxy.Url = " http: / / basesmcdev2 / sites / tester1
SharePoint GridView Groupby count Hi All, I am using SharePoint Grid view in my custom aspx page where i have an option group the SharePoint Grid view by various factor such as title, id , user etc. Here i need to using System; using System.Data; using System.Text; using System.Web.UI.WebControls; using Microsoft.SharePoint; using Microsoft.SharePoint.WebControls; using SPFormUtilities; namespace ListItemPermissionsReport { public class ReportListingByUser : LayoutsPageBase { protected SPGridView grdListItemPermissions; protected Label lblError string UrlEncode( string text) { return Server.UrlEncode(text).Replace( "+" , "%20" ); } private void initPage() { / / Create a DataTable to hold the list item permission report data. DataTable dt = new DataTable(); dt.Columns.Add( "User" ); dt.Columns.Add( "ItemLink" ); dt.Columns.Add( "Permissions" ); / / Use an SPGridView