C# .NET - how can save httppostedfile in viewstate
Asked By tulip m on 07-Jan-12 06:53 AM
I want to save httppostedfile in viewstate or sassion that can use it after page postback
I want to save file in another part of page but I lose fileUp.PostedFile
plz help meeeee
kalpana aparnathi replied to tulip m on 07-Jan-12 06:59 AM
dipa ahuja replied to tulip m on 07-Jan-12 07:08 AM
Session["file"] = FileUpload1.PostedFile;
Suchit shah replied to tulip m on 07-Jan-12 07:09 AM
I think when ever yo get the File Path at that time you can take the File Path in to the Session or ViewState but you can not take it whole collection of httppostedfile because it occured when the page posted so at the time of post it contain the value after word it lost the value ... so you can take individual value of posted file like filename , filepath, fileextension and then after when ever you required in page at that time you can save it
Sreekumar P replied to tulip m on 07-Jan-12 07:12 AM
Actually u can store the PostedFile in session like this Session["file"]=File1.PostedFile.
But no Use, :).
Even u can cast this in another page. Think that you selected file will be valid only in one Postback, after one postback it will be lost.
So u have to save in the first postback.
Riley K replied to tulip m on 07-Jan-12 07:38 AM
You might be asking this question to save the state of the fileupload on postback
Due to security reasons fileupload does not save the posted file name in its viewstate, so the file will be lost on postback
But one way would be to save the file name in database during the first postback and path in viewstate object
tulip m replied to tulip m on 08-Jan-12 12:27 AM
So I undrestand that I can't do anything,just save it befor postback
It's very bad
tulip m replied to tulip m on 08-Jan-12 12:52 AM
guys I found it
at first :
Session["file"] = fileUp.PostedFile;
and after post back :
HttpPostedFile oHttpPostedFile = (HttpPostedFile) Session["file"];
It get me something like fileUp.PostedFile;
thanks for all replayes and tnks dipa ahuja