Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/294.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在执行spsitedataquery后获取项来自的子网站_C#_Sharepoint_Sharepoint 2010 - Fatal编程技术网

C# 在执行spsitedataquery后获取项来自的子网站

C# 在执行spsitedataquery后获取项来自的子网站,c#,sharepoint,sharepoint-2010,C#,Sharepoint,Sharepoint 2010,我有以下代码: SPSiteDataQuery query = new SPSiteDataQuery(); //Get List query string query.Lists = "<Lists BaseType='1'></Lists>"; query.ViewFields = "<FieldRef Name='Title' Nullable='TRUE'

我有以下代码:

SPSiteDataQuery query = new SPSiteDataQuery();

                //Get List query string

                query.Lists = "<Lists BaseType='1'></Lists>";


                query.ViewFields = "<FieldRef Name='Title' Nullable='TRUE' />";
                query.ViewFields += "<FieldRef Name='ContentTypeId' Nullable='TRUE' />";
                query.ViewFields += "<FieldRef Name='ContentType' Nullable='TRUE' />";
                query.ViewFields += "<FieldRef Name='ArticleStartDate' Nullable='TRUE' />";
                query.ViewFields += "<FieldRef Name='Synopsis' Nullable='TRUE' />";
                query.ViewFields += "<FieldRef Name='PublishingRollupImage' Nullable='TRUE' />";
                query.ViewFields += "<FieldRef Name='Location' Nullable='TRUE' />";
                query.ViewFields += "<FieldRef Name='LOBGroup' Nullable='TRUE' />";
                query.Query = "<Where>" +
                                  "<Contains>" +
                                    "<FieldRef Name='ContentType'/>" +
                                    "<Value Type='Text'>DCP_Article</Value>" +
                                  "</Contains>" +
                                "</Where>";



                query.Query += "<OrderBy>" +
                                    "<FieldRef Name='ArticleStartDate' Descending='TRUE' />" +
                                "</OrderBy>";


                query.RowLimit = Convert.ToUInt32(loadsize);
                query.Webs = "<Webs Scope='Recursive' />";


                //Get Site Data from web
                DataTable dt = web.GetSiteData(query);
在我的结果中,我希望获得项目来自的子网站,我知道如果我使用query.ViewFields+=;我可以获得该项目的完整url,但是否存在我可以直接获取其来源的子网站的情况?大概是这样的: query.ViewFields+=

试试看:

query.ViewFields += "<ProjectProperty Name=\"Title\" />";
有关详细信息,请参阅:

使用ProjectProperty标记可以包括站点属性。ProjectProperty标记的Name属性标识特定属性,并可能包含以下值之一:

标题-包含项目的网站的标题

WebId—包含该项的网站的GUID

尝试:

有关详细信息,请参阅:

使用ProjectProperty标记可以包括站点属性。ProjectProperty标记的Name属性标识特定属性,并可能包含以下值之一:

标题-包含项目的网站的标题

WebId—包含该项的网站的GUID


您可以依靠EncodedAbsUrl和FileRef来检索web。第一个将包含项目的整个路径,第二个仅包含部分(如果我记得清楚的话)。因此,执行子字符串应该为您提供项目所在web的路径


很抱歉,我面前没有虚拟机,但如果您使用SharePoint Explorer/Manager之类的工具,您将看到所有隐藏的列表项字段,并能够获取最接近您的解决方案的字段,但我认为依靠EncodedAbsUrl和FileRef最安全可靠

您可以同时依靠EncodedAbsUrl和FileRef来检索web。第一个将包含项目的整个路径,第二个仅包含部分(如果我记得清楚的话)。因此,执行子字符串应该为您提供项目所在web的路径


很抱歉,我面前没有虚拟机,但如果您使用SharePoint Explorer/Manager之类的工具,您将看到所有隐藏的列表项字段,您将能够获取最接近您的解决方案的字段,但我最安全的依靠EncodedAbsUrl和FileRef的方法是可靠的,还有一个选择是使用WebId列,它将包含在您的结果集中。 这是一个guid,可用于打开结果来自的web:

Guid webGuid = new Guid(row["WebId"].ToString());
using(SPWeb web = SPContext.Current.Site.AllWebs[webGuid])
{
     //Do some thing with the SPWeb
}

还有一个选择是使用WebId列,它将包含在您的结果集中。 这是一个guid,可用于打开结果来自的web:

Guid webGuid = new Guid(row["WebId"].ToString());
using(SPWeb web = SPContext.Current.Site.AllWebs[webGuid])
{
     //Do some thing with the SPWeb
}