Use of htmlinputfile WITHOUT the fileinput on an ASP.NET page

GornHorse

Well-known member
Joined
May 27, 2003
Messages
105
Location
Australia
I have a web-based project written in VB.NET. I am creating a text file which needs to be saved to the web server that i am running the project from.

I like the look and ease-of-use of the system.web.ui.htmlcontrols.htmlinputfile item for retrieving the file name that i wish to upload. However, i do not want to have the control visibly seen on the aspx page. The reason for this is because the user does not know that the file is being created, and the file name is dynamically created.

What i would like to know is how i can instantiate the PostedFile property of the htmlinputfile without putting this control on the aspx page.

This may sound like a silly question, but its really confusing me. The code i have is below:

halfdetailsfile = "UpdatedDetails_" & tempdate & "_" & staticMemberID & ".txt"

Write the new details to a text file.
Dim savelocation As String
savelocation = Server.MapPath("UpdatedDetails" & "\" & halfdetailsfile)
Dim htmlfile As New Web.UI.HtmlControls.HtmlInputFile()
htmlfile.Value = halfdetailsfile
Dim blah = htmlfile.PostedFile()
htmlfile.PostedFile.SaveAs(savelocation)

The problem is that even though i have assigned a string to the value property of the htmlinputfile (htmlfile), it will not actually instantiate a postedfile. Therefore, blah returns "nothing". As a result, i receive an error when i try to save the postedfile to the savelocation address.

If someone could please offer me some much needed assistance, and quickly would be extremely helpful, then that would be great.

Thanks very much.

Regards,
Michelle
 
Hi Robby,

Thanks for your quick reply. Just one quick query, when declaring htmlfile as a member of the class, do you mean...

Protected WithEvents htmlfile As Web.UI.HtmlControls.HtmlInputFile()

Or, can i declare htmlfile as a member of the class within the sub? Not that it really matters, I guess, but for future reference (and as a learning curve), is that code what you refer to when you said "declare htmlfile as a member of the class and include WithEvents"?

This last little tip will go a long way.

Thanks once again!

Michelle
 
To be a member of the Class means to declare it at the top so that all subs can see it, if you declare it in a sub then its a local variable and only that sub can see it.
 
Hi Robby,

I still cannot get this to work. I have declared the htmlfile using the code in my last post at the top, but it still wont create the reference, as blah is still returning Nothing.

Do you possibly have any further advice with this?

Thanks again!

Michelle
 
Hi Robby,

Never mind... i figured out that it wasnt going to serve my porpose anyway. Ive fixed my error - see in post 72601 if youre interested.

Thanks, however, for your knowledge, as i am a beginner to vb net, and in fact to object oriented programming, so your input regarding the htmlinputfile i have applied to other situations.

Thanks very much for your help.

Regards,
Michelle
 
Back
Top