<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Welcome to ShanthaKumar&#039;s Blog, SharePoint and more... &#187; SPQuery</title>
	<atom:link href="http://www.ktskumar.com/blog/tag/spquery/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.ktskumar.com</link>
	<description>more Points to Share....</description>
	<lastBuildDate>Tue, 13 Dec 2011 17:36:09 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Retrieve all folders with sub-folders from SharePoint List</title>
		<link>http://www.ktskumar.com/blog/2009/07/retrieve-all-folders-from-list/</link>
		<comments>http://www.ktskumar.com/blog/2009/07/retrieve-all-folders-from-list/#comments</comments>
		<pubDate>Fri, 10 Jul 2009 18:23:16 +0000</pubDate>
		<dc:creator>Shantha Kumar</dc:creator>
				<category><![CDATA[MOSS]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Folders]]></category>
		<category><![CDATA[FSObjType]]></category>
		<category><![CDATA[RecursiveAll]]></category>
		<category><![CDATA[SPQuery]]></category>

		<guid isPermaLink="false">http://ktskumar.com/blog/?p=166</guid>
		<description><![CDATA[In this post, I’ll show you how to get all the folders including subfolders from Document Library or List in sharepoint. This is just easy, by using SPQuery object and setting ViewAttributes property in it; we can retrieve only the folders from the SharePoint List, with a single condition. Now I’ll show you a code, [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, I’ll show you how to get all the folders including subfolders from Document Library or List in sharepoint.</p>
<p>This is just easy, by using SPQuery object and setting ViewAttributes property in it; we can retrieve only the folders from the SharePoint List, with a single condition. Now I’ll show you a code,</p>
<div class="codecss">
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; color: #2b91af; mso-no-proof: yes;">SPSite</span><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> site = <span style="color: #2b91af;">SPContext</span>.Current.Site;</span><br />
<span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="font-family: Georgia;"><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; color: #2b91af; mso-no-proof: yes;">SPWeb</span><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> web = <span style="color: #2b91af;">SPContext</span>.Current.Web;</span></span></span></p>
<p><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; color: #2b91af; mso-no-proof: yes;">SPList</span><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> list = web.Lists[<span style="color: #a31515;">"Shared Documents"</span>];</span>
</p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; color: #2b91af; mso-no-proof: yes;">SPQuery</span><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> query = <span style="color: blue;">new</span> <span style="color: #2b91af;">SPQuery</span>();</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; color: green; mso-no-proof: yes;">//Condition to check the item type is folder or not</span><br />
<span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">query.Query = <span style="color: #a31515;">&#8220;&lt;Where&gt;&lt;Eq&gt;&lt;FieldRef Name=&#8217;FSObjType&#8217;/&gt;&lt;Value Type=&#8217;Lookup&#8217;&gt;1&lt;/Value&gt;&lt;/Eq&gt;&lt;/Where&gt;&#8221;</span>; </span>
</p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; color: green; mso-no-proof: yes;">//Get all the items including subfolders from the list</span><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">query.ViewAttributes = <span style="color: #a31515;">&#8220;Scope=&#8217;RecursiveAll&#8217;&#8221;</span>;</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; color: #2b91af; mso-no-proof: yes;"> </span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; color: green; mso-no-proof: yes;">//Retrieve the items based on Query</span><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; color: #2b91af; mso-no-proof: yes;"> </span><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; color: #2b91af; mso-no-proof: yes;">SPListItemCollection</span><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> items = list.GetItems(query);</span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; color: blue; mso-no-proof: yes;">string</span><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> folderDetails=<span style="color: #a31515;">&#8220;&#8221;</span>;<span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span></span></p>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; color: green; mso-no-proof: yes;">//Get the name and Url for the folder</span><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span><br />
<span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; color: blue; mso-no-proof: yes;">foreach</span><span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> (<span style="color: #2b91af;">SPListItem</span> item <span style="color: blue;">in</span> items)</span><br />
<span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">{</span><br />
<span style="font-size: 10.0pt; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"><span style="mso-spacerun: yes;"> </span>folderDetails += <span style="color: #a31515;">&#8220;Folder Name:&#8221;</span> + item.Name + <span style="color: #a31515;">&#8220;&lt;br/&gt;Folder URL:&#8221;</span> + web.Url + <span style="color: #a31515;">&#8220;/&#8221;</span> + item.Url + <span style="color: #a31515;">&#8220;&lt;br/&gt;&#8221;</span>;<span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span><span style="mso-spacerun: yes;"> </span></span><br />
<span style="font-size: 10.0pt; line-height: 115%; font-family: &quot;Courier New&quot;; mso-no-proof: yes;">}</span>
</p>
</div>
<p class="MsoNormal" style="margin-bottom: .0001pt; line-height: normal; mso-layout-grid-align: none; text-autospace: none;"><span style="font-size: 10.0pt; line-height: 115%; font-family: &quot;Courier New&quot;; mso-no-proof: yes;"> </span></p>
<p>In <strong>Query</strong> property of <strong>SPQuery</strong> object, we have to set the condition of “<strong>FSObjType</strong>” is equal to 0, this is the &#8220;<strong>Item Type</strong>&#8221; value for the folder, the list items or documents contain the Item Type value as 1.</p>
<p>And then <strong>Scope=’RecursiveAll’</strong> is nothing but to retrieve all the items and folders from the list or library.</p>
<p>I&#8217;ll hope this post help you all about retrieving all the folders from the SharePoint List or Library.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ktskumar.com/blog/2009/07/retrieve-all-folders-from-list/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>Download all files from SharePoint Library</title>
		<link>http://www.ktskumar.com/blog/2009/04/download-all-files-from-sharepoint-library/</link>
		<comments>http://www.ktskumar.com/blog/2009/04/download-all-files-from-sharepoint-library/#comments</comments>
		<pubDate>Sat, 11 Apr 2009 15:35:07 +0000</pubDate>
		<dc:creator>Shantha Kumar</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[All Files]]></category>
		<category><![CDATA[Download]]></category>
		<category><![CDATA[Library]]></category>
		<category><![CDATA[SPQuery]]></category>

		<guid isPermaLink="false">http://ktskumar.wordpress.com/?p=152</guid>
		<description><![CDATA[Now, we are going to see how we can download all documents(incluing sub folders) from SharePoint Library. First of all,we have get all documents from SharePoint Library. The following code help us to get all the documents including Subfolders. //Get the Document Library and its view SPList list = web.Lists["Test Document"]; SPView view = list.Views["All [...]]]></description>
			<content:encoded><![CDATA[<p>Now, we are going to see how we can download all documents(incluing sub folders) from SharePoint Library.</p>
<p>First of all,we have get all documents from SharePoint Library. The following code help us to get all the documents including Subfolders.<br />
<span style="color:#99cc00;"><span style="color:#339966;">//Get the Document Library and its view</span><br />
</span><span style="color:#000080;">SPList list = web.Lists["Test Document"];<br />
SPView view = list.Views["All Documents"];</span><br />
<span style="color:#339966;">//Query all documents in Library including files under subfolders<br />
</span><span style="color:#000080;">SPQuery squery = new SPQuery(view);<br />
squery.ViewAttributes = &#8220;Scope=&#8221;Recursive&#8221;";<br />
SPListItemCollection items = list.GetItems(squery);</span></p>
<p>Now we have to write a code for downloaing documents,<br />
<span style="color:#339966;">//Read all documents and write those files to Local System</span><br />
<span style="color:#000080;">foreach (SPListItem item in items)<br />
{<br />
byte[] binfile = item.File.OpenBinary();<br />
FileStream fstream = new FileStream(&#8220;F:\&#8221; + item.File.Name, FileMode.Create, FileAccess.ReadWrite);<br />
fstream.Write(binfile, 0, binfile.Length);<br />
fstream.Close();<br />
}</span></p>
<p>By using the above code snippets, we can download all document from SharePoint Library.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.ktskumar.com/blog/2009/04/download-all-files-from-sharepoint-library/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

