<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.silverlight.net/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>Programming with .NET - General</title><link>http://forums.silverlight.net/forums/17.aspx</link><description>General discussions around authoring Silverlight .NET applications.</description><dc:language>en</dc:language><generator>CommunityServer 2007 (Build: 20416.853)</generator><item><title>Re: silverlight problem of upload file by HttpWebRequest to HTTP ASP.NET website</title><link>http://forums.silverlight.net/forums/thread/157016.aspx</link><pubDate>Wed, 07 Jan 2009 02:55:17 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:157016</guid><dc:creator>jackykkk</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/157016.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=157016</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;&lt;BLOCKQUOTE&gt;&lt;div&gt;&lt;img src="/Themes/silverlight/images/icon-quote.gif"&gt; &lt;strong&gt;IanBlackburn:&lt;/strong&gt;&lt;/div&gt;&lt;div&gt;&lt;/p&gt;&lt;p&gt;Have you tried using a Wcf service instead and passing a byte array through to the server?&lt;/p&gt;&lt;p&gt;&lt;/div&gt;&lt;/BLOCKQUOTE&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Hi IanBlackburn:&lt;/p&gt;&lt;p&gt;Thanks for your comment.&lt;/p&gt;&lt;p&gt;However, I do not think it is the problem to pass a byte array. In fact, I use the traditional webpage file upload because I do not want to copy the whole file in memory. Hence, I use HttpWebRequest to simulate the function of webbrowser.&lt;/p&gt;&lt;p&gt;In my code, only a 4Kbyte array is necessary. The major upload function is&lt;/p&gt;&lt;p&gt;&amp;nbsp;====================================================&lt;/p&gt;&lt;p&gt;&amp;nbsp;// Write out the file contents&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; byte[] buffer = new Byte[checked((uint)Math.Min(4096,&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; (int)m_UploadFile.Length))];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; int bytesRead = 0;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; using (FileStream fileStream = m_UploadFile.OpenRead())&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; requestStream.Write(buffer, 0, bytesRead);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;&lt;p&gt;&lt;br /&gt;====================================================&lt;/p&gt;&lt;p&gt;In fact, the same function works in normal WPF window application to upload the same file to the same webpage.&lt;/p&gt;&lt;p&gt;I note that the silverlight webbrowser will allocate memory even much more than the size of the upload&amp;nbsp; file. However, the WPF window app will not allocate too much memory during upload file (view in task manager). I think the implementation of the &amp;quot;HttpWebReques&amp;quot; has some critical difference between SilverLight and WPF.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;I put my testing code in&amp;nbsp; &amp;quot;http://cid-c5a160856855eb99.skydrive.live.com/self.aspx/Public/UploadTest.zip&amp;quot;.&lt;/p&gt;&lt;p&gt;I my very thanks if you can give me some comment. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;Moreover, will the Wcf service provide function direclty upload file?&lt;/p&gt;&lt;p&gt;I am not familiar wcf very much. Just have basic idea in the formal MSDN document. As I know, it is still need to load data in memory and sent to remote server through the public remote function parameters.&lt;/p&gt;&lt;p&gt;Would you provide some example link to me how wcf to directly upload file to remote server?&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;Thank you very much. &lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: silverlight problem of upload file by HttpWebRequest to HTTP ASP.NET website</title><link>http://forums.silverlight.net/forums/thread/156552.aspx</link><pubDate>Tue, 06 Jan 2009 10:24:50 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:156552</guid><dc:creator>IanBlackburn</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/156552.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=156552</wfw:commentRss><description>&lt;p&gt;Have you tried using a Wcf service instead and passing a byte array through to the server?&lt;/p&gt;</description></item><item><title>silverlight problem of upload file by HttpWebRequest to HTTP ASP.NET website</title><link>http://forums.silverlight.net/forums/thread/156475.aspx</link><pubDate>Tue, 06 Jan 2009 08:04:52 GMT</pubDate><guid isPermaLink="false">d0d632c8-a6f7-4f68-b0ce-26aaafd62132:156475</guid><dc:creator>jackykkk</dc:creator><slash:comments>0</slash:comments><comments>http://forums.silverlight.net/forums/thread/156475.aspx</comments><wfw:commentRss>http://forums.silverlight.net/forums/commentrss.aspx?SectionID=17&amp;PostID=156475</wfw:commentRss><description>&lt;p&gt;Hello:&lt;/p&gt;&lt;p&gt;&amp;nbsp;I have a problem to use silverlight to&amp;nbsp; upload file to HTTP ASP.NET website.&lt;/p&gt;&lt;p&gt;The&amp;nbsp; ASP.NET website is very simple. The form has one &amp;quot;asp:FileUpload&amp;quot; object. The form has been marked to &amp;#39;method=&amp;quot;post&amp;quot; enctype=&amp;quot;multipart/form-data&amp;quot;&amp;#39;.&lt;/p&gt;&lt;p&gt;The web.config has marked&amp;nbsp; &amp;#39;&amp;lt;httpRuntime maxRequestLength=&amp;quot;2097151&amp;quot; executionTimeout=&amp;quot;1800&amp;quot;/&amp;gt;&amp;#39; to allow large request data length.&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;The form &amp;quot;Page_Load&amp;quot; saves file data&lt;/p&gt;&lt;p&gt;&amp;nbsp;===============================&lt;/p&gt;&lt;br /&gt;&lt;p&gt;foreach (string file in Request.Files.AllKeys)&lt;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Request.Files[file].SaveAs(.......);&lt;br /&gt;}&lt;/p&gt;&lt;br /&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;=================================&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;The problem is that, I write a SilverLight client to update files to the website through the above ASP.NET webform.&lt;/p&gt;&lt;p&gt;If the file size is not too large (&amp;lt;100M), the upload function is OK.&lt;/p&gt;&lt;p&gt;if the file size is too large, the&amp;nbsp;  upload function will fail.&lt;/p&gt;&lt;p&gt;&amp;nbsp;I have tested the Webform by directly access the form in browser and using the &amp;quot;File&amp;quot; object to upload the file. It is OK in pure HTTP/HTML/ASP.NET way. Just fail in Silverlight. The control is still not passed to the Webform &amp;quot;Page_Load&amp;quot;.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;In silverlight , I have tried HttpWebRequest to upload file both method will fail in same way for large file.&lt;/p&gt;&lt;p&gt;I note that when upload file, the browser (both IE6 and Firefox3) memory usage will increase very much (view in task manager) . &lt;/p&gt;&lt;p&gt;However, uplaod file in webform page, the&amp;nbsp; browser memory usage will NOT increase too much .&lt;/p&gt;&lt;p&gt;I think the problem is in the silverlight plugin.&lt;/p&gt;&lt;p&gt;&amp;nbsp;Anyone have idea about this problem.&lt;/p&gt;&lt;p&gt;&amp;nbsp;Thank you very much.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;testing system -&lt;/p&gt;&lt;p&gt;OS - Vista x64,&lt;/p&gt;&lt;p&gt;memory 4G,&lt;/p&gt;&lt;p&gt;VisualStudio2008+sp1+silverlight2 SDK,&lt;/p&gt;&lt;p&gt;Testing in&amp;nbsp; VisualStudio development webserver process.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item></channel></rss>