<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="https://www.infopathdev.com:443/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Code</title><link>https://www.infopathdev.com:443/forums/45.aspx</link><description /><dc:language>en</dc:language><generator>CommunityServer 2007 SP3 (Build: 31118.962)</generator><item><title>Infopath 2003, file attachment control and byte arrays</title><link>https://www.infopathdev.com:443/forums/thread/39812.aspx</link><pubDate>Sat, 21 Mar 2009 12:25:36 GMT</pubDate><guid isPermaLink="false">033a2e2d-04e2-4a9d-be01-a4634161eefd:39812</guid><dc:creator>henrikfromsweden</dc:creator><slash:comments>0</slash:comments><comments>https://www.infopathdev.com:443/forums/thread/39812.aspx</comments><wfw:commentRss>https://www.infopathdev.com:443/forums/commentrss.aspx?SectionID=45&amp;PostID=39812</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;
&lt;p&gt;I have been banging my head against this for the whole weekend now. We have a project where we need to use Infopath 2003 to submit data to a SharePoint list (not the issue here). The form also needs to append a file to the list item (the issue). There is a web service in Sharepoint, AddAttachment, where I can pass a Base64 encoded string and Sharepoint will save the a new attachment. The problem is that the file attachment control has a variable length &lt;a class="" href="http://blogs.msdn.com/infopath/archive/2004/03/18/92221.aspx" target="_blank"&gt;header&lt;/a&gt; infront of the actual file. &lt;/p&gt;
&lt;p&gt;I have been able to get the filename, and other information out from the header (see code below), but the actual problem is that I need to strip the header away and still maintain the Base64 encoding doing this in VBScript or Jscript.&lt;/p&gt;
&lt;p&gt;Any suggestions?&lt;/p&gt;
&lt;p&gt;Regards,&lt;/p&gt;
&lt;p&gt;// Henrik&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Code to extract filename:&lt;/p&gt;
&lt;p&gt;&amp;#39;File control name:&lt;br /&gt;Set node = XDocument.DOM.documentElement.selectSingleNode(&amp;quot;/my:myFields/my:field1&amp;quot;)&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;If(node.text &amp;lt;&amp;gt; &amp;quot;&amp;quot;) Then&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;#39;typecast the node to base64 as Infopath doesn&amp;#39;t do this in node definition&lt;br /&gt;&amp;nbsp;&amp;nbsp;node.DataType = &amp;quot;bin.base64&amp;quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;#39;convert base64 node value to binary and store in nodeValue byte array&lt;br /&gt;&amp;nbsp;&amp;nbsp;nodeValue = node.nodeTypedValue&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;#39;Convert the bytearray to hex&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;dim convertByteArrayToHexString &lt;br /&gt;&amp;nbsp;&amp;nbsp;convertByteArrayToHexString = &amp;quot;&amp;quot;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;For intCounter = 1 to LenB(nodeValue)&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;convertByteArrayToHexString = convertByteArrayToHexString &amp;amp; Right(&amp;quot;0&amp;quot; &amp;amp; Hex(AscB(MidB(nodeValue, intCounter, 1))), 2)&amp;nbsp;&amp;nbsp; &lt;br /&gt;&amp;nbsp;&amp;nbsp;Next&amp;nbsp; &lt;br /&gt;&lt;br /&gt;&amp;#39;Extract the filename buffer size first (the filename buffer has a different size depending on length of the filename)&lt;br /&gt;&amp;#39;41 and 47 is the position in the header where this information is located. 41 is actaully position 20 in the bytearray (20*2) + 1(arrays in vbscript starts on 1)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;filenameBuffer = getFilenameBuffer(convertByteArrayToHexString,41,47)&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;&amp;#39;And then the&amp;nbsp;actual filename&amp;nbsp;&lt;br /&gt;&amp;#39;49 is the start position for the filename,&amp;nbsp;the end is calculated&lt;br /&gt;&amp;nbsp;&amp;nbsp;filename = getFileName(convertByteArrayToHexString,49,filenameBuffer*4 + 49 - 2)&lt;br /&gt;&lt;/p&gt;
&lt;p&gt;Function getFilenameBuffer(data,startLoop,stopLoop)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;dim k&lt;br /&gt;&amp;nbsp;dim filenameBuffer&lt;br /&gt;&amp;nbsp;for k = startLoop to stopLoop step 2&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;dim y1&lt;br /&gt;&amp;nbsp;&amp;nbsp;dim y2&lt;br /&gt;&amp;nbsp;&amp;nbsp;dim y3&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;y1 = Mid(data,k,2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;y2 = CLng(&amp;quot;&amp;amp;h&amp;quot; &amp;amp; y1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;y3 = y3 + Int(y2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;filenameBuffer = y3&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;next&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;getFilenameBuffer = filenameBuffer&lt;/p&gt;
&lt;p&gt;End Function&lt;/p&gt;
&lt;p&gt;Function getFileName(data,startLoop, stopLoop)&lt;/p&gt;
&lt;p&gt;&amp;nbsp;dim k &lt;br /&gt;&amp;nbsp;dim filename&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;for k = startLoop to stopLoop step 4&lt;br /&gt;&amp;nbsp;&amp;nbsp;dim h1&lt;br /&gt;&amp;nbsp;&amp;nbsp;dim h2&lt;br /&gt;&amp;nbsp;&amp;nbsp;dim h3&lt;br /&gt;&amp;nbsp;&amp;nbsp;&lt;br /&gt;&amp;nbsp;&amp;nbsp;h1 = Mid(data,k,2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;h2 = CLng(&amp;quot;&amp;amp;h&amp;quot; &amp;amp; h1)&lt;br /&gt;&amp;nbsp;&amp;nbsp;h3 = Chr(h2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;if(h3 &amp;lt;&amp;gt; &amp;quot;&amp;quot;) then&lt;br /&gt;&amp;nbsp;&amp;nbsp; filename = filename &amp;amp; Cstr(h3)&lt;br /&gt;&amp;nbsp;&amp;nbsp;end if&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;next&lt;br /&gt;&amp;nbsp;&lt;br /&gt;&amp;nbsp;getFileName = filename&lt;/p&gt;
&lt;p&gt;End Function&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>