查询整个网站集共享点
我有一个 Web 部件,位于顶级站点下的 2-3 个子站点。我需要查询顶级网站集中的列表和同一级别的列表,我想它可以通过 SPSiteDataquery...我对此有一些困惑,我可以编写可以查询这两个列表的单个查询吗...
此查询的范围是 sitecollection,因此这意味着它将查看 sitecollection 中的所有列表。如果我的 CAML 查询对于这两个列表都相同...它应该可以工作吗?
让我通过我的代码进行解释:
SPSite mySite = SPControl.GetContextSite(Context);
SPWeb myWeb = SPControl.GetContextWeb(Context);
SPSiteDataQuery qry = new SPSiteDataQuery();
qry.Lists = "<Lists BaseType='0' />";
qry.Query = "<Where><Contains><FieldRef Name='Country'/><Value Type='Text'>" + strcount + "</Value></Contains></Where>";
qry.ViewFields = "<FieldRef Name='Capital' Nullable='TRUE'/><FieldRef Name='Currency' Nullable='TRUE'/>";
qry.Webs = "<Webs Scope='SiteCollection' />";
DataTable dt = myWeb.GetSiteData(qry);
现在我需要顶级站点列表中的货币和同一级别列表中的资本。这可能吗?或者我误解了 SPSiteDataQuery...?
I have a webpart which is 2-3 subsites down the top level site. I need to query the list which is in top site collection and one at the same level,I guess its possible through SPSiteDataquery...I have some confusion related to it can i write single query which can query both these list....
The scope of this query is sitecollection so that means it wud going to look into all list in sitecollection..and if my CAML query is same for both these lists ...it should work?
let me explain through my code:
SPSite mySite = SPControl.GetContextSite(Context);
SPWeb myWeb = SPControl.GetContextWeb(Context);
SPSiteDataQuery qry = new SPSiteDataQuery();
qry.Lists = "<Lists BaseType='0' />";
qry.Query = "<Where><Contains><FieldRef Name='Country'/><Value Type='Text'>" + strcount + "</Value></Contains></Where>";
qry.ViewFields = "<FieldRef Name='Capital' Nullable='TRUE'/><FieldRef Name='Currency' Nullable='TRUE'/>";
qry.Webs = "<Webs Scope='SiteCollection' />";
DataTable dt = myWeb.GetSiteData(qry);
Now i need currency from list which is in top level site and Capital from the list which is at same level. Is this possible? or I misunderstood SPSiteDataQuery...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您走在正确的道路上,可以检索不同网站中列表的结果。以下示例演示如何从默认“任务”或“工作流程任务”列表中检索项目,并使用在根级别和子站点内创建的任务列表。
我使用硬编码 URL 编写了它,以便您可以在控制台应用程序中运行它进行测试,但是当您放置此内容时,您可以将 using 语句替换为
SPWeb web = SPContext.Current.Web;
在 Web 部件内。其他一些值得考虑的事情:
You are on the right track and it is possible to retrieve results for lists in different webs. The following example shows how to retrieve items from the default 'Tasks' or 'Workflow Tasks' lists and works with task lists created at the root level and within a sub site.
I've written it using a hardcoded URL so you can run it inside a console application for testing but you can replace the using statements with something like
SPWeb web = SPContext.Current.Web;
when you put this inside a web part.A few other things worth considering: