Skip to main content

Microsoft Silverlight

Unanswered Question silverlight problem of upload file by HttpWebRequest to HTTP ASP.NET websiteRSS Feed

(0)

jackykkk
jackykkk

Member

Member

30 points

8 Posts

silverlight problem of upload file by HttpWebRequest to HTTP ASP.NET website

Hello:

 I have a problem to use silverlight to  upload file to HTTP ASP.NET website.

The  ASP.NET website is very simple. The form has one "asp:FileUpload" object. The form has been marked to 'method="post" enctype="multipart/form-data"'.

The web.config has marked  '<httpRuntime maxRequestLength="2097151" executionTimeout="1800"/>' to allow large request data length.

 

 The form "Page_Load" saves file data

 ===============================


foreach (string file in Request.Files.AllKeys)
{
     Request.Files[file].SaveAs(.......);
}


 

=================================

 

The problem is that, I write a SilverLight client to update files to the website through the above ASP.NET webform.

If the file size is not too large (<100M), the upload function is OK.

if the file size is too large, the  upload function will fail.

 I have tested the Webform by directly access the form in browser and using the "File" 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 "Page_Load".

 

In silverlight , I have tried HttpWebRequest to upload file both method will fail in same way for large file.

I note that when upload file, the browser (both IE6 and Firefox3) memory usage will increase very much (view in task manager) .

However, uplaod file in webform page, the  browser memory usage will NOT increase too much .

I think the problem is in the silverlight plugin.

 Anyone have idea about this problem.

 Thank you very much.

 

 testing system -

OS - Vista x64,

memory 4G,

VisualStudio2008+sp1+silverlight2 SDK,

Testing in  VisualStudio development webserver process.


 

 

IanBlackburn
IanBlack...

Contributor

Contributor

2333 points

371 Posts

Re: silverlight problem of upload file by HttpWebRequest to HTTP ASP.NET website

Have you tried using a Wcf service instead and passing a byte array through to the server?

(If this has answered your question, "Mark as Answer" - many thanks)

Cheers

Ian Blackburn
SilverlightForBusiness.net

jackykkk
jackykkk

Member

Member

30 points

8 Posts

Re: silverlight problem of upload file by HttpWebRequest to HTTP ASP.NET website

 

IanBlackburn:

Have you tried using a Wcf service instead and passing a byte array through to the server?

 

Hi IanBlackburn:

Thanks for your comment.

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.

In my code, only a 4Kbyte array is necessary. The major upload function is

 ====================================================

 // Write out the file contents
                    byte[] buffer = new Byte[checked((uint)Math.Min(4096,
                                             (int)m_UploadFile.Length))];
                    int bytesRead = 0;
                    using (FileStream fileStream = m_UploadFile.OpenRead())
                    {
                        while ((bytesRead = fileStream.Read(buffer, 0, buffer.Length)) != 0)
                            requestStream.Write(buffer, 0, bytesRead);
                    }


====================================================

In fact, the same function works in normal WPF window application to upload the same file to the same webpage.

I note that the silverlight webbrowser will allocate memory even much more than the size of the upload  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 "HttpWebReques" has some critical difference between SilverLight and WPF.

I put my testing code in  "http://cid-c5a160856855eb99.skydrive.live.com/self.aspx/Public/UploadTest.zip".

I my very thanks if you can give me some comment.

 

 Moreover, will the Wcf service provide function direclty upload file?

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.

Would you provide some example link to me how wcf to directly upload file to remote server?

 

Thank you very much.

 

 

  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities