Thursday, January 22, 2015

SPSiteDataQuery - The property Query contains an invalid value


I had an assignment to create some functionality to fetch information from various SharePoint Lists to perform some operations. Everything was working fine, until I have been asked to make it parameterized based on Content Types, which can be supplied by Admin/Content Author via Web Part Properties. Below is the Sample Code Snippet:

using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
    using (SPWeb web = site.OpenWeb())
    {
         SPSiteDataQuery query = new SPSiteDataQuery();
         query.ViewFields = @"";
         query.Webs = @"";

         DataTable dataTable = web.GetSiteData(query);

         GridView1.DataSource = dataTable;
         GridView1.DataBind();
     }
}

So, I modified my code as follows:

using (SPSite site = new SPSite(SPContext.Current.Site.ID))
{
    using (SPWeb web = site.OpenWeb())
    {
         SPSiteDataQuery query = new SPSiteDataQuery();
         query.ViewFields = @"";
         query.Query = @"query.Query%20%3D%20%40%22%20%20%20%3CWhere%3E%0A%20%3CEq%3E%0A%20%20%20%3CFieldRef%20Name%3D%27ContentType%27%20%2F%3E%0A%20%20%20%3CValue%20Type%3D%27Text%27%3EContact%3C%2FValue%3E%0A%20%3C%2FEq%3E%0A%3C%2FWhere%3E%22%3B";

         query.Webs = @"";

         DataTable dataTable = web.GetSiteData(query);

         GridView1.DataSource = dataTable;
         GridView1.DataBind();
     }
}

This change was based on the new requirement but after that I started getting the following error:

------------------------------------------------------------

Microsoft.SharePoint.SPException was unhandled by user code
  HResult=-2146232832
  Message=The property Query contains an invalid value.
  Source=Microsoft.SharePoint
  ErrorCode=-2146232832
  StackTrace:
       at Microsoft.SharePoint.SPSiteDataQuery.ReportInvalidProperty(Exception ex, String strProperty)
       at Microsoft.SharePoint.SPSiteDataQuery.ValidateXmlProperty(String strXml, String strPropertyName, String strTag, String strTag2, String strTag3)
       at Microsoft.SharePoint.SPSiteDataQuery.get_ViewXml()
       at Microsoft.SharePoint.SPWeb.GetSiteData(SPSiteDataQuery query)...........
       
  InnerException: 

------------------------------------------------------------

This freaked me out since with CAML Query Builder, my query was working fine. I searched a lot and applied some fixes mentioned in some of the posts online, but none of them worked. 

So, after spending several hours and trying various stuff with the Code, I managed to resolve it by deleting all extra non-readable characters as follows:

query.Query = @"Contact";

I am not sure why SPSiteDataQuery causes this issue whereas I have been writing queries with above mentioned readability and clarity with SPQuery Class.

Enjoy!!! :-)

Wednesday, January 19, 2011

SPMetal Tool - What you didn't know

I was using SPMetal Tool and facing an issue. I cam across a nice article describing SPMetal Tool and its usage.

http://blog.walshie.me/2010/07/28/sharepoint-2010-linq-spmetal-what-you-dont-know/

Thursday, December 23, 2010

Deploying Microsoft Office Solutions by Using Visual Studio 2010 and Windows Installer

Here is a very detailed article and code samples to create and deploy Office Solutions.

http://blogs.msdn.com/b/vsto/archive/2010/08/19/deploying-microsoft-office-solutions-by-using-visual-studio-2010-and-windows-installer.aspx

Monday, August 16, 2010

How to Build a SharePoint 2010 Farm on a Single Machine with Local Accounts

http://blogs.kraftkennedy.com/index.php/2010/08/09/how-to-build-a-sharepoint-2010-farm-on-a-single-machine-with-local-accounts/

Monday, December 28, 2009

Sharepoint 2010 Beta Developer Training Kit

Overview

The SharePoint 2010 Beta Developer Training Kit provides developers with deep guidance on how to develop for SharePoint 2010. Through PowerPoint decks, Hands-On Labs, Source Code, and Instructor-Led Videos, the developer kit walks you through an array of important developer topics--including Developer Roadmap, Visual Studio tooling, Workflow, Business Connectivity Services, and much, much more.

Quick Details
File Name: SharePoint2010Developer.exe
Version: 1.0
Date Published: 12/14/2009
Language: English
Download Size: 41.9 MB

Source:- http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=bfd1603b-7550-4b8e-be85-4215a5069b90


Tuesday, December 15, 2009

Installing SharePoint 2010

Hi,

I was installing SharePoint 2010 and found following nice and helpful article.

http://blogs.msdn.com/opal/archive/2009/10/25/sharepoint-2010-pre-requisites-download-links.aspx