Last post Sep 18, 2010 05:44 AM by touseefahmad
Jun 17, 2007 08:27 PM|Bonekrusher|LINK
I have a file upload control on my webform. When I want to use it to select a text file. I will not be uploaded the file however, I will need the value of the path so I can open the text file with the streamreader. I then will pass the value of the text
file to a database. How do I get the value of the fileupload textbox?
Here is my code so far:
Dim FILENAME As String = NEED VALUE OF FILEUPLOAD TEXTBOX VALUE HERE
Dim myfile As String
Dim objStreamReader As StreamReader
objStreamReader = File.OpenText(myfile.Text)
Dim contents As String = objStreamReader.ReadToEnd()
t.Text = contents
Jun 17, 2007 09:03 PM|mbanavige|LINK
the full path for the users file can be seen in the property: FileUpload.PostedFile.FileName
Dim userPath As String
If Not Me.FileUpload1.PostedFile Is Nothing Then
userPath = Me.FileUpload1.PostedFile.FileName
But if you can read this property, then the file has been uploaded. Also, you cannot use this path to read the file directly from the users file system with a streamreader. When you use this path on the server, it will refer to your server file system
and not the clients file system.
You can read the uploaded file using:
Jun 17, 2007 11:49 PM|Bonekrusher|LINK
Thanks you, you have been a great help.
My work around was to upload the file to the server, read it with the streamreader and then delete the file.
I will try "Me.FileUpload1.PostedFile.FileName" to read the file directly.
Jul 06, 2008 04:16 PM|danishjee|LINK
how can i assign my path run time to fileupload
if fileupload1.PostedFile is nothing then
get the file "~/Imgs/NoImage.jpg" and assing to fileupload.
how can i do this thing
Sep 18, 2010 05:44 AM|touseefahmad|LINK
Thanks a lot Mike. Your answer was very helpful.