typecast session variable to fileupload object

ollydsouza

Member
Joined
Mar 2, 2012
Messages
6
Programming Experience
10+
Hi,

To save the FileUpload Object state on postbacks, Im storing the name of the file in a session so on subsequent postbacks the FileUpload object needs to be intialized by the session variable for which I need to typecast. how do I do this? Any help?
something like:

FileUpload1 = (FileUpload) Session["FileUpload1"];Thanks,
 
In VB.Net casting is done using DirectCast keyword or CType function.

If you need C# support you can for example try the C# forums here C# Developer Forums
 
HI JohnH,

Thanks for the response. I dont need c# support...was trying to convert a c# snippet into VB.
to achieve this:


//If first time page is submitted and we have file in FileUpload control but not in session // Store the values to SEssion Object if (Session["FileUpload1"] == null && FileUpload1.HasFile) { Session["FileUpload1"] = FileUpload1; Label1.Text = FileUpload1.FileName; } // Next time submit and Session has values but FileUpload is Blank // Return the values from session to FileUpload else if (Session["FileUpload1"] != null && (! FileUpload1.HasFile)) { FileUpload1 = (FileUpload) Session["FileUpload1"]; Label1.Text = FileUpload1.FileName; } // Now there could be another sictution when Session has File but user want to change the file // In this case we have to change the file in session object else if (FileUpload1.HasFile) { Session["FileUpload1"] = FileUpload1; Label1.Text = FileUpload
In VB.Net casting is done using DirectCast keyword or CType function.

If you need C# support you can for example try the C# forums here C# Developer Forums
 
was trying to convert a c# snippet into VB.
Have you tried an online code converter ?
 
I would try a web search for 'c# vb.net online converter' if I needed one.
 
Back
Top