<?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; Download Document</title>
	<atom:link href="http://www.ktskumar.com/blog/tag/download-document/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>Download Document from SharePoint Library using WebService</title>
		<link>http://www.ktskumar.com/blog/2009/03/download-document-from-sharepoint-library-using-webservice/</link>
		<comments>http://www.ktskumar.com/blog/2009/03/download-document-from-sharepoint-library-using-webservice/#comments</comments>
		<pubDate>Sun, 08 Mar 2009 15:24:48 +0000</pubDate>
		<dc:creator>Shantha Kumar</dc:creator>
				<category><![CDATA[General]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[WebService]]></category>
		<category><![CDATA[Copy]]></category>
		<category><![CDATA[Copy WebService]]></category>
		<category><![CDATA[Download Document]]></category>
		<category><![CDATA[GetItem]]></category>

		<guid isPermaLink="false">http://ktskumar.wordpress.com/?p=80</guid>
		<description><![CDATA[In this post, I am going to explain about downloading a document from sharepoint library using webservice, For that we need following things, Read the contents from Document, located in SharePoint Library Create and store the contents on a new document in Local Machine To get the contents from Document under Sharepoint library,we shall use [...]]]></description>
			<content:encoded><![CDATA[<p>In this post, I am going to explain about downloading a document from sharepoint library using webservice, For that we need following things,</p>
<ul>
<li>Read the contents from Document, located in SharePoint Library</li>
<li>Create and store the contents on a new document in Local Machine</li>
</ul>
<p>To get the contents from Document under Sharepoint library,we shall use the GetItem method of Copy WebService. This method will generate a Byte array of the document,  and then pass it as a parameter on  FileStream Contrutor to create a new document.</p>
<p>The Syntax for the GetItem method as follows,</p>
<p><span style="font-family:Courier New;"><span class="keyword" style="font-family:Courier New;">public</span> <strong>uint</strong> <span class="identifier">GetItem</span> ( 	<strong>string</strong> Source<span class="parameter">Url</span>, 	<span class="keyword">out</span> <strong>FieldInformation</strong>[] <span class="parameter">Fields</span>, 	<span class="keyword">out</span> <strong>byte</strong>[] <span class="parameter">Stream</span> )</span></p>
<h2><strong>Parameters,</strong></h2>
<p><strong>SourceUrl:</strong><br />
A String that contains the absolute source (on the server to which the SOAP request is sent) of the document that is to be retrieved.</p>
<p><strong>Fields:</strong><br />
An array of FieldInformation objects, passed as an out parameter, that represent the fields and the corresponding field values that can be copied from the retrieved document.</p>
<p><strong>Stream:</strong><br />
An array of Bytes, passed as an out parameter, that is a base-64 representation of the retrieved document&#8217;s binary data.</p>
<p><strong>Return Value:</strong><br />
A UInt32 that returns 0 to indicate that the operation has completed. (There are also two out parameters containing an array of CopyResult objects and an array of FieldInformation objects.)</p>
<p>Below i’m providing a code for downloading a document from SharePoint Library,</p>
<p><span style="color:#008000;font-family:0;">//Copy WebService Settings</span><br />
<span style="color:#000080;"> string webUrl = “http://localhost:1000?;<br />
WSCopy.Copy copyService = new WSCopy.Copy();<br />
copyService.Url = webUrl+”/_vti_bin/copy.asmx”;<br />
copyService.Credentials = System.Net.CredentialCache.DefaultCredentials;</span></p>
<p><span style="color:#008000;font-family:0;">//Source and Destination Document URLs</span><br />
<span style="color:#000080;"> string sourceUrl = &#8220;http://localhost:1000/Shared Documents/Sample.doc&#8221;;<br />
string destinationUrl = &#8220;C:\DocumentsSample.doc&#8221;;</span></p>
<p><span style="color:#008000;font-family:0;">//Variables for Reading metadata&#8217;s of a document</span><br />
<span style="color:#000080;"> WSCopy.FieldInformation fieldInfo = new WSCopy.FieldInformation();<br />
WSCopy.FieldInformation[] fieldInfoArray = { fieldInfo };<br />
WSCopy.CopyResult cResult1 = new WSCopy.CopyResult();<br />
WSCopy.CopyResult cResult2 = new WSCopy.CopyResult();<br />
WSCopy.CopyResult[] cResultArray = { cResult1, cResult2 };</span></p>
<p><span style="color:#008000;font-family:0;">//Receive a Document Contents  into Byte array (filecontents)</span><br />
<span style="color:#000080;"> byte[] fileContents = new Byte[4096];<br />
copyService.GetItem(sourceUrl, out fieldInfoArray, out fileContents); </span></p>
<p><span style="color:#008000;font-family:0;">//Create a new file and write contents to that document</span><br />
<span style="color:#000080;"> FileStream fStream = new FileStream(destinationUrl, FileMode.Create, FileAccess.ReadWrite);<br />
fStream.Write(fileContents, 0, fileContents.Length);<br />
fStream.Close();</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.ktskumar.com/blog/2009/03/download-document-from-sharepoint-library-using-webservice/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
	</channel>
</rss>

