views:

313

answers:

2

Hello!

Maybe it's the worst practice in the world, but I was wondering wich's the best way to "keep alive" the InputStream of the FileUpload Control.

I would give you one example. Let's assume you have the FileUpload control in one WebForm, and you want process it in the next WebForm (after Response.Redirect).

It would be great (unless for the memory) to have something similar to:

Session["PostedFile"] = this.FileUpload.PostedFile.InputStream.

Unfortunately, this results in:

System.ObjectDisposedException

Thanks in advance.

+1  A: 

Why don't you read the stream first and then add it to the session?

hunter
Thanks!. Because of the cost of reading a very large image or file. In some way it's a work that has been done before by the framework but maybe it's the only solution.Thanks again!
vote me up, please?
hunter
A: 

I have the same problem. I would like to retrive the PostedFile from stored session.

Below is code for storing file to session Session.Add("OverWriteImage", fuUploadNew.PostedFile.InputStream);

And I use following code to read PostedFile from session. HttpPostedFile Image = (HttpPostedFile)(Session["OverWriteImage"]);

I get the Image from session, but content of Image is not same as it stored. As the other attribute like ContentLength, FileName are get matched but not the acutal Image.

Anand