<?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>programming &#8211; Kodono</title>
	<atom:link href="https://blog.kodono.info/wordpress/tag/programming/feed/" rel="self" type="application/rss+xml" />
	<link>https://blog.kodono.info/wordpress</link>
	<description>Pour tous les technophiles</description>
	<lastBuildDate>Fri, 05 Apr 2013 08:39:41 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.1</generator>
	<item>
		<title>Create a file into Sharepoint document librairies with the Copy.asmx web service [Javascript]</title>
		<link>https://blog.kodono.info/wordpress/2011/12/21/create-a-file-into-sharepoint-document-librairies-with-the-copy-asmx-web-service-javascript/</link>
					<comments>https://blog.kodono.info/wordpress/2011/12/21/create-a-file-into-sharepoint-document-librairies-with-the-copy-asmx-web-service-javascript/#comments</comments>
		
		<dc:creator><![CDATA[Aymeric]]></dc:creator>
		<pubDate>Wed, 21 Dec 2011 16:33:19 +0000</pubDate>
				<category><![CDATA[Niveau intermédiaire]]></category>
		<category><![CDATA[Programmation]]></category>
		<category><![CDATA[english]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[programming]]></category>
		<category><![CDATA[sharepoint]]></category>
		<guid isPermaLink="false">http://blog.kodono.info/wordpress/?p=808</guid>

					<description><![CDATA[This is the English version of my previous article EDIT: I&#8217;ve created a JavaScript API for Sharepoint that handles the file creation. Just look at http://aymkdn.github.com/SharepointPlus/symbols/%24SP%28%29.html#.createFile Did you know it&#8217;s possible to create a file from scratch and to add it into a shared documents library of Sharepoint, and only with Javascript ? To do [&#8230;]]]></description>
										<content:encoded><![CDATA[<div lang="en"><strong><em>This is the English version of my previous article</em></strong></p>
<p><strong>EDIT:</strong> I&#8217;ve created a JavaScript API for Sharepoint that handles the file creation. Just look at <a href="http://aymkdn.github.com/SharepointPlus/symbols/%24SP%28%29.html#.createFile">http://aymkdn.github.com/SharepointPlus/symbols/%24SP%28%29.html#.createFile</a></p>
<p>Did you know it&#8217;s possible to create a file from scratch and to add it into a shared documents library of Sharepoint, and only with Javascript ?</p>
<p>To do it we&#8217;ll use the &#8220;copy.asmx&#8221; web service with the &#8220;CopyIntoItems&#8221; function.<br />
If you check <strong>http://your_sharepoint/_vti_bin/copy.asmx?op=CopyIntoItems</strong> you&#8217;ll see that we have several details about the &#8220;CopyIntoItems&#8221; function. Unfortunately it&#8217;s very difficult to find any information regarding this on the Web, and specially for Javascript&#8230;</p>
<p>So, here is the solution to create a file, e.g. an Excel file (.xls) with a regular HTML table, and we&#8217;re going to save it to this library: &#8220;http://your_sharepoint/Shared Documents/&#8221; (Note: I&#8217;m using jQuery for the AJAX requests).</p>
<pre class="brush: javascript">
// The file content must be encoded into Base64. To do it I use the function available on my blog (http://blog.kodono.info/wordpress/2011/07/27/midi-code-encoder-decoder-en-base64-pour-javascript-programmation/)
function encode_b64(a,b,c,d,e,f){b="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";c='=';for(d=f='';e&#038;=3,a.charAt(d++)||(b=';=',e);f+=b.charAt(63&#038;c>>++e*2))c=c&lt;&lt;8|a.charCodeAt(d-=!e);return f}

// "Upload" is the name of our function to do the job
// txtContent is a plain text, the content of our file
// destinationUrl is the full path URL to the document library (with the filename included)
function Upload(txtContent, destinationUrl) {
    var jsStream = encode_b64(txtContent);
    var soapEnv  = &quot;&lt;?xml version=\&quot;1.0\&quot; encoding=\&quot;utf-8\&quot;?>&quot;
                  +&quot;&lt;soap:Envelope xmlns:xsi=\&quot;http://www.w3.org/2001/XMLSchema-instance\&quot; xmlns:xsd=\&quot;http://www.w3.org/2001/XMLSchema\&quot; xmlns:soap=\&quot;http://schemas.xmlsoap.org/soap/envelope/\&quot;>&quot;
                  +&quot;&lt;soap:Body>&quot;
                  +&quot;&lt;CopyIntoItems xmlns=\&quot;http://schemas.microsoft.com/sharepoint/soap/\&quot;>&quot;
                  +&quot;&lt;SourceUrl>http://null&lt;/SourceUrl>&quot;
                  +&quot;&lt;DestinationUrls>&lt;string>&quot;+destinationUrl+&quot;&lt;/string>&lt;/DestinationUrls>&quot;
                  +&quot;&lt;Fields>&lt;FieldInformation Type=&apos;File&apos; />&lt;/Fields>&quot;
                  +&quot;&lt;Stream>&quot;+jsStream+&quot;&lt;/Stream>&quot;
                  +&quot;&lt;/CopyIntoItems>&quot;
                  +&quot;&lt;/soap:Body>&quot;
                  +&quot;&lt;/soap:Envelope>&quot;;
    jQuery.ajax({
        url: &quot;http://your_sharepoint/_vti_bin/copy.asmx&quot;,
        type: &quot;POST&quot;,
        dataType: &quot;xml&quot;,
        data: soapEnv,
        beforeSend: function(xhr) { xhr.setRequestHeader(&apos;SOAPAction&apos;, &apos;http://schemas.microsoft.com/sharepoint/soap/CopyIntoItems&apos;); },
        contentType: &quot;text/xml; charset=\&quot;utf-8\&quot;&quot;
    });
}

Upload("&lt;html>&lt;table>&lt;tr>&lt;th>Colonne 1&lt;/th>&lt;th>Colonne B&lt;/th>&lt;/tr>&lt;tr>&lt;td>Total:&lt;/td>&lt;td>1500&lt;/td>&lt;/tr>&lt;/table>&lt;/html>","http://your_sharepoint/Shared Documents/test.xls");
</pre>
<p>Then, when you&#8217;ll click on the new &#8220;test.xls&#8221; file, your web browser will want to open it with Excel. MS Excel should show you a warning message, but just click YES and you&#8217;ll see your table inside the sheet !</p>
<p>Of course you can create any type of files (.txt, .jpg, .doc, &#8230;) and with any content.</p>
<p>Related links:</p>
<ul>
<li><a href="http://blog.stuartwhiteford.com/?p=86">http://blog.stuartwhiteford.com/?p=86</a></li>
<li><a href="http://stackoverflow.com/questions/7976329/sharepoint-copyintoitems-soap-message-in-objective-c">http://stackoverflow.com/questions/7976329/sharepoint-copyintoitems-soap-message-in-objective-c</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/copy.copy.copyintoitems%28v=office.12%29.aspx">http://msdn.microsoft.com/en-us/library/copy.copy.copyintoitems%28v=office.12%29.aspx</a></li>
</ul>
</div>
]]></content:encoded>
					
					<wfw:commentRss>https://blog.kodono.info/wordpress/2011/12/21/create-a-file-into-sharepoint-document-librairies-with-the-copy-asmx-web-service-javascript/feed/</wfw:commentRss>
			<slash:comments>4</slash:comments>
		
		
			</item>
	</channel>
</rss>
