开发者

problem with SPQuery for whole sitecollection?

开发者 https://www.devze.com 2022-12-17 06:40 出处:网络
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.

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);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消