Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

  • Moderators
Posted
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.
Visit...Bassic Software
Posted

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

Posted

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...