SPSiteDataQuery在设置Query属性时抛出异常

时间:2011-08-26 17:09:11

标签: sharepoint

我在SharePoint网站中查询多个任务列表。我可以检索结果,直到我设置Query属性并指定OrderBy子句。详细的例外和代码粘贴在下面。感谢任何帮助

   private void doTasks(SPWeb currentWeb, SPSiteDataQuery q)
    {

        q.Query =
             "<OrderBy>" +
             "   <FieldRef Name='Priority' />" +
             "   <FieldRef Name='DueDate' />" +
             "</OrderBy>";


        // Specify the view fields.
        q.ViewFields = "<FieldRef Name='Title' Type='Text'/>";
        q.ViewFields += "<FieldRef Name='AssignedTo' Type='User' Nullable='TRUE' />";
        q.ViewFields += "<FieldRef Name='PercentComplete' Type='Number' Nullable='TRUE'/>";
        results = currentWeb.GetSiteData(q);

        if (results.Rows.Count > 0)
        {
                 //blah!
        }
    }

[COMException(0x80020009):0x80020009]    Microsoft.SharePoint.Library.SPRequestInternalClass.CrossListQuery(String bstrUrl,String bstrXmlWebs,String bstrXmlLists,String bstrXmlQuery,ISP2DSafeArrayWriter pCallback,Object&amp; pvarColumns)+0    Microsoft.SharePoint.Library.SPRequest.CrossListQuery(String bstrUrl,String bstrXmlWebs,String bstrXmlLists,String bstrXmlQuery,ISP2DSafeArrayWriter pCallback,Object&amp; pvarColumns)+177

[SPException]    Microsoft.SharePoint.SPGlobal.HandleComException(COMException comEx)+27428978    Microsoft.SharePoint.Library.SPRequest.CrossListQuery(String bstrUrl,String bstrXmlWebs,String bstrXmlLists,String bstrXmlQuery,ISP2DSafeArrayWriter pCallback,Object&amp; pvarColumns)+27812419    Microsoft.SharePoint.SPWeb.GetSiteData(SPSiteDataQuery查询)+521    StoraEnso.Collaboration.WebParts.SubSiteItemAggregator.SubSiteItemAggregator.doTasks(SPWeb currentWeb,SPSiteDataQuery q)+189    StoraEnso.Collaboration.WebParts.SubSiteItemAggregator.SubSiteItemAggregator.Render(HtmlTextWriter writer)+441    Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter输出,WebPart部分)+43

[WebPartException]    Microsoft.SharePoint.WebPartPages.SPChrome.RenderPartContents(HtmlTextWriter输出,WebPart部分)+19826502    Microsoft.SharePoint.WebPartPages.SPChrome.RenderWebPart(HtmlTextWriter输出,WebPart部分)+64    Microsoft.SharePoint.WebPartPages.WebPartZone.RenderZoneCell(HtmlTextWriter输出,布尔bMoreParts,WebPart部分)+1997    Microsoft.SharePoint.WebPartPages.WebPartZone.RenderWebParts(HtmlTextWriter输出,ArrayList webParts)+508    Microsoft.SharePoint.WebPartPages.WebPartZone.Render(HtmlTextWriter输出)+1000    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children)+240    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children)+240    System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer)+42    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children)+240    System.Web.UI.HtmlControls.HtmlForm.RenderChildren(HtmlTextWriter writer)+253    System.Web.UI.HtmlControls.HtmlForm.Render(HtmlTextWriter输出)+87    System.Web.UI.HtmlControls.HtmlForm.RenderControl(HtmlTextWriter writer)+53    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children)+240    System.Web.UI.HtmlControls.HtmlContainerControl.Render(HtmlTextWriter writer)+42    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children)+240    System.Web.UI.Control.RenderChildrenInternal(HtmlTextWriter writer,ICollection children)+240    System.Web.UI.Page.Render(HtmlTextWriter writer)+38    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint,Boolean includeStagesAfterAsyncPoint)+4240

4 个答案:

答案 0 :(得分:2)

在迁移过程中,一些页面布局使用SPSiteDataQuery在不同的Web上查询ContentTypes以获取内容。该代码在SP2007中运行良好,但在SP2010中它抛出异常,如下所述:

<强>解决方案

确保您使用的订单字段包含在SPSiteDataQuery.ViewFields属性中。就这么简单!

答案 1 :(得分:0)

OrderBy中包装<Query></Query>子句。

答案 2 :(得分:0)

如果删除AssignedToPercentComplete FieldRef,它是否有效?我问,因为如果您查询站点中的所有列表,大多数将不包含AssignedTo和PercentComplete字段。这可能会导致错误。

q.Lists的价值是多少?如果您尚未设置q.Lists,请尝试:

q.Lists = "<Lists ServerTemplate=\"107\" />"

答案 3 :(得分:0)

如果其他人遇到类似的问题:在我发现CAML查询的最后一行不能是空行之前,我花了两个小时。换句话说,在CAML查询结束时不得有任何换行符。删除换行符立即解决了问题。