problem with SPQuery for whole sitecollection?
HI, Can we use SPQuery to query whole site collection. Means I have a list which is in different site so is it possible to use SPQuery for that or I need to use SPSiteDataQuery.
I know SPSiteDataQuery would work in this case but I don't wanna search all the lists as I know the name of the list and in SPSiteDataquery开发者_JAVA百科 i can't mention the list name and in my case list name is unique in whole site collection. If not SPQuery whats the best method to query my list . I don't wana use Guid over here....
Any suggestions? Thanks,
If you know the exact position of the list (i.e. the (sub)web it is in), you can just use
using(SPWeb otherWeb = SPContext.Current.Site.OpenWeb("urlofweblistisin"))
{
SPList yourList = otherWeb.Lists["YourListName"];
SPListItemCollection = yourList.GetItems(yourSPQuery);
}
精彩评论