<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	>
<channel>
	<title>Comments on: Building a SPQuery ViewFields string</title>
	<atom:link href="http://www.wirwar.com/blog/2008/08/01/building-a-spquery-viewfields-string/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.wirwar.com/blog/2008/08/01/building-a-spquery-viewfields-string/</link>
	<description>Blah blah SharePoint blah blah Development blah blah</description>
	<pubDate>Thu,  9 Sep 2010 02:52:02 +0000</pubDate>
	<generator>http://wordpress.org/?v=2.6.2</generator>
		<item>
		<title>By: Bespoke Website Development</title>
		<link>http://www.wirwar.com/blog/2008/08/01/building-a-spquery-viewfields-string/#comment-22053</link>
		<dc:creator>Bespoke Website Development</dc:creator>
		<pubDate>Thu, 04 Mar 2010 16:50:10 +0000</pubDate>
		<guid isPermaLink="false">http://www.wirwar.com/blog/?p=75#comment-22053</guid>
		<description>I've been doing SPContext.Current.Web.Lists["meeting"] style queries, this helps me now!</description>
		<content:encoded><![CDATA[<p>I&#8217;ve been doing SPContext.Current.Web.Lists["meeting"] style queries, this helps me now!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Beekermd03</title>
		<link>http://www.wirwar.com/blog/2008/08/01/building-a-spquery-viewfields-string/#comment-16599</link>
		<dc:creator>Beekermd03</dc:creator>
		<pubDate>Wed, 05 Aug 2009 18:01:40 +0000</pubDate>
		<guid isPermaLink="false">http://www.wirwar.com/blog/?p=75#comment-16599</guid>
		<description>Satish:
To remove the ID and Created columns from the GetItems Query, remove them from the DataTable object.  In yourcase, dt.Columns.Remove("ID") and dt.Columns.Remove("Created").

Hope this helps someone!</description>
		<content:encoded><![CDATA[<p>Satish:<br />
To remove the ID and Created columns from the GetItems Query, remove them from the DataTable object.  In yourcase, dt.Columns.Remove(&#8221;ID&#8221;) and dt.Columns.Remove(&#8221;Created&#8221;).</p>
<p>Hope this helps someone!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Raghu Iyer</title>
		<link>http://www.wirwar.com/blog/2008/08/01/building-a-spquery-viewfields-string/#comment-12274</link>
		<dc:creator>Raghu Iyer</dc:creator>
		<pubDate>Mon, 06 Apr 2009 16:42:05 +0000</pubDate>
		<guid isPermaLink="false">http://www.wirwar.com/blog/?p=75#comment-12274</guid>
		<description>Hi Leon, 

Thanks for your inputs on IAlertNotifyHandler, i have been trying to resolve this issue from long time now.

Will give this a shot and let you know how it goes.

Thanks
Raghu Iyer</description>
		<content:encoded><![CDATA[<p>Hi Leon, </p>
<p>Thanks for your inputs on IAlertNotifyHandler, i have been trying to resolve this issue from long time now.</p>
<p>Will give this a shot and let you know how it goes.</p>
<p>Thanks<br />
Raghu Iyer</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Satish Reddy</title>
		<link>http://www.wirwar.com/blog/2008/08/01/building-a-spquery-viewfields-string/#comment-8926</link>
		<dc:creator>Satish Reddy</dc:creator>
		<pubDate>Fri, 10 Oct 2008 18:40:27 +0000</pubDate>
		<guid isPermaLink="false">http://www.wirwar.com/blog/?p=75#comment-8926</guid>
		<description>Thank you much,I am disposing SPWeb and SPSite objects in finally block,thats is my sample code .Even I digged in other blogs also,at the end I came to know ID and Created columns can't be eliminated in SPQuery.

Once again Thank so much for ur response..</description>
		<content:encoded><![CDATA[<p>Thank you much,I am disposing SPWeb and SPSite objects in finally block,thats is my sample code .Even I digged in other blogs also,at the end I came to know ID and Created columns can&#8217;t be eliminated in SPQuery.</p>
<p>Once again Thank so much for ur response..</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Leon Zandman</title>
		<link>http://www.wirwar.com/blog/2008/08/01/building-a-spquery-viewfields-string/#comment-8900</link>
		<dc:creator>Leon Zandman</dc:creator>
		<pubDate>Thu, 09 Oct 2008 19:48:33 +0000</pubDate>
		<guid isPermaLink="false">http://www.wirwar.com/blog/?p=75#comment-8900</guid>
		<description>@Satish: A query using SPQuery always returns SPListItem instances with the "ID" and "Created" fields filled. This is by design. The ViewFields property only allows you to return additional fields. So I'm afraid you cannot prevent those fields from ending up in your DataTable.

Also I notice your sample code doesn't dispose the SPWeb and SPSite instances properly. And did you notice you can call my BuildViewFieldsXml() function like this:

oSPQuery.ViewFields = BuildViewFieldsXml("Title", "ListName");

You don't have to create that separate array, like you do.</description>
		<content:encoded><![CDATA[<p>@Satish: A query using SPQuery always returns SPListItem instances with the &#8220;ID&#8221; and &#8220;Created&#8221; fields filled. This is by design. The ViewFields property only allows you to return additional fields. So I&#8217;m afraid you cannot prevent those fields from ending up in your DataTable.</p>
<p>Also I notice your sample code doesn&#8217;t dispose the SPWeb and SPSite instances properly. And did you notice you can call my BuildViewFieldsXml() function like this:</p>
<p>oSPQuery.ViewFields = BuildViewFieldsXml(&#8221;Title&#8221;, &#8220;ListName&#8221;);</p>
<p>You don&#8217;t have to create that separate array, like you do.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Satish Reddy</title>
		<link>http://www.wirwar.com/blog/2008/08/01/building-a-spquery-viewfields-string/#comment-8897</link>
		<dc:creator>Satish Reddy</dc:creator>
		<pubDate>Thu, 09 Oct 2008 18:57:09 +0000</pubDate>
		<guid isPermaLink="false">http://www.wirwar.com/blog/?p=75#comment-8897</guid>
		<description>Hi,

This is my code 

public DataTable GetSiteDeatils()
        {

            String strSiteURL = "http:///Configuration/Pages/default.aspx";

            SPSite oSPSite = new SPSite(strSiteURL);
            SPWeb oSPWeb;
            

            
             oSPWeb = oSPSite.OpenWeb();

             SPQuery oSPQuery = new SPQuery();

              
            string[] fields ={"Title","ListName" };
            oSPQuery.ViewFields = BuildViewFieldsXml(fields);

        
           SPListItemCollection oSPListItemCollection = oSPWeb.Lists["ListDetails"].GetItems(oSPQuery);
            DataTable dt = oSPListItemCollection.GetDataTable();
            


            return dt;
        
        }

        public static string BuildViewFieldsXml(params string[] fieldNames)
        {

            const string TEMPLATE = @"";
            StringBuilder sb = new StringBuilder();

            foreach (string fieldName in fieldNames)
            {
                sb.AppendFormat(TEMPLATE, fieldName);
            }
            return sb.ToString();
        }

Its returning  Title and Listname in datatable.But, its additionaly including ID and Created  Columns .

How to elininate ID and Created Columns..

Regards
Satish</description>
		<content:encoded><![CDATA[<p>Hi,</p>
<p>This is my code </p>
<p>public DataTable GetSiteDeatils()<br />
        {</p>
<p>            String strSiteURL = &#8220;http:///Configuration/Pages/default.aspx&#8221;;</p>
<p>            SPSite oSPSite = new SPSite(strSiteURL);<br />
            SPWeb oSPWeb;</p>
<p>             oSPWeb = oSPSite.OpenWeb();</p>
<p>             SPQuery oSPQuery = new SPQuery();</p>
<p>            string[] fields ={&#8221;Title&#8221;,&#8221;ListName&#8221; };<br />
            oSPQuery.ViewFields = BuildViewFieldsXml(fields);</p>
<p>           SPListItemCollection oSPListItemCollection = oSPWeb.Lists["ListDetails"].GetItems(oSPQuery);<br />
            DataTable dt = oSPListItemCollection.GetDataTable();</p>
<p>            return dt;</p>
<p>        }</p>
<p>        public static string BuildViewFieldsXml(params string[] fieldNames)<br />
        {</p>
<p>            const string TEMPLATE = @&#8221;";<br />
            StringBuilder sb = new StringBuilder();</p>
<p>            foreach (string fieldName in fieldNames)<br />
            {<br />
                sb.AppendFormat(TEMPLATE, fieldName);<br />
            }<br />
            return sb.ToString();<br />
        }</p>
<p>Its returning  Title and Listname in datatable.But, its additionaly including ID and Created  Columns .</p>
<p>How to elininate ID and Created Columns..</p>
<p>Regards<br />
Satish</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Valentin Rossi</title>
		<link>http://www.wirwar.com/blog/2008/08/01/building-a-spquery-viewfields-string/#comment-7526</link>
		<dc:creator>Valentin Rossi</dc:creator>
		<pubDate>Tue, 05 Aug 2008 21:25:07 +0000</pubDate>
		<guid isPermaLink="false">http://www.wirwar.com/blog/?p=75#comment-7526</guid>
		<description>Thanks. Code snippets like this one are very helpful.</description>
		<content:encoded><![CDATA[<p>Thanks. Code snippets like this one are very helpful.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dotan</title>
		<link>http://www.wirwar.com/blog/2008/08/01/building-a-spquery-viewfields-string/#comment-7506</link>
		<dc:creator>Dotan</dc:creator>
		<pubDate>Mon, 04 Aug 2008 13:15:41 +0000</pubDate>
		<guid isPermaLink="false">http://www.wirwar.com/blog/?p=75#comment-7506</guid>
		<description>Thanks Leon! Just what I was looking for...</description>
		<content:encoded><![CDATA[<p>Thanks Leon! Just what I was looking for&#8230;</p>
]]></content:encoded>
	</item>
</channel>
</rss>
