GornHorse Posted May 27, 2003 Posted May 27, 2003 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 it's 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 Quote
Moderators Robby Posted May 27, 2003 Moderators Posted May 27, 2003 If you declare htmlfile as a member of the class and include WithEvents it should work fine. Quote Visit...Bassic Software
GornHorse Posted May 27, 2003 Author Posted May 27, 2003 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 Quote
Moderators Robby Posted May 27, 2003 Moderators Posted May 27, 2003 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 it's a local variable and only that sub can see it. Quote Visit...Bassic Software
GornHorse Posted May 28, 2003 Author Posted May 28, 2003 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 won't create the reference, as 'blah' is still returning Nothing. Do you possibly have any further advice with this? Thanks again! Michelle Quote
GornHorse Posted May 28, 2003 Author Posted May 28, 2003 Hi Robby, Never mind... i figured out that it wasn't going to serve my porpose anyway. I've fixed my error - see in post 72601 if you're 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 Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.