pass HtmlInputFile from page to page - impossible?

G

Guest

I am coding a forum and am having problems passing around the attachment file
(as an HtmlInputFile) from page to page. Sometimes the users may want to
preview their posts with the attachment specs (filesize, content-type, etc..)
before submitting.

i have tried storing it in a session like so:
HtmlInputFile uploadFile = new HtmlInputFile();
Session["ForumAttachFileContents"] = uploadFile.PostedFile;

Then retrieving it, though I can't seem to figure out if the session is
actually getting the variable because I try to cast on the next page like so
but it doesn't work:
attachmentFile = (HtmlInputFile)(Session["ForumAttachFileContents"]);

I get an error saying cast is not valid. Most forums/tutorials speak of
ways to upload, however it is not done after passing the file around. It's
simply a click and save right away process, which I do not want. Please
help, thank you.
 
P

Peter Rilling

Maybe what you can do is to temporarily save the file to disk, then save the
file's metadata in an object that you can pass from page to page (through
the session object). I personally would not trust the existence of an
uploaded file for any time past the current page. There might be some way
to do it, but you would have more control over the information if you were
to immediately decouple the file from the posted data.
 
G

Guest

R Reyes said:
I am coding a forum and am having problems passing around the attachment file
(as an HtmlInputFile) from page to page. Sometimes the users may want to
preview their posts with the attachment specs (filesize, content-type, etc..)
before submitting.

i have tried storing it in a session like so:
HtmlInputFile uploadFile = new HtmlInputFile();
Session["ForumAttachFileContents"] = uploadFile.PostedFile;

Then retrieving it, though I can't seem to figure out if the session is
actually getting the variable because I try to cast on the next page like so
but it doesn't work:
attachmentFile = (HtmlInputFile)(Session["ForumAttachFileContents"]);

you are not making the right cast. HtmlInputFile.PostedFile is of type
HttpPostedFile. of course it's an invalid cast.
 
G

Guest

Can't find a way to use HttpPostedFile. What should i include? I already
have System.IO. And would it be possible to just use the same code I posted
earlier with the HttpPostedFile as the cast or am I supposed to go about this
another way?

Daniel Jin said:
R Reyes said:
I am coding a forum and am having problems passing around the attachment file
(as an HtmlInputFile) from page to page. Sometimes the users may want to
preview their posts with the attachment specs (filesize, content-type, etc..)
before submitting.

i have tried storing it in a session like so:
HtmlInputFile uploadFile = new HtmlInputFile();
Session["ForumAttachFileContents"] = uploadFile.PostedFile;

Then retrieving it, though I can't seem to figure out if the session is
actually getting the variable because I try to cast on the next page like so
but it doesn't work:
attachmentFile = (HtmlInputFile)(Session["ForumAttachFileContents"]);

you are not making the right cast. HtmlInputFile.PostedFile is of type
HttpPostedFile. of course it's an invalid cast.
I get an error saying cast is not valid. Most forums/tutorials speak of
ways to upload, however it is not done after passing the file around. It's
simply a click and save right away process, which I do not want. Please
help, thank you.
 
G

Guest

Got it. I was trying to do this:
HttpPostedFile attachmentFile = new HttpPostedFile();

but realized you said "type" and so it should be like this:
HttpPostedFile attachmentFile;

Thanks for your help.

Daniel Jin said:
R Reyes said:
I am coding a forum and am having problems passing around the attachment file
(as an HtmlInputFile) from page to page. Sometimes the users may want to
preview their posts with the attachment specs (filesize, content-type, etc..)
before submitting.

i have tried storing it in a session like so:
HtmlInputFile uploadFile = new HtmlInputFile();
Session["ForumAttachFileContents"] = uploadFile.PostedFile;

Then retrieving it, though I can't seem to figure out if the session is
actually getting the variable because I try to cast on the next page like so
but it doesn't work:
attachmentFile = (HtmlInputFile)(Session["ForumAttachFileContents"]);

you are not making the right cast. HtmlInputFile.PostedFile is of type
HttpPostedFile. of course it's an invalid cast.
I get an error saying cast is not valid. Most forums/tutorials speak of
ways to upload, however it is not done after passing the file around. It's
simply a click and save right away process, which I do not want. Please
help, thank you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top