Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get value from FILE INPUT object 1

Status
Not open for further replies.

LonnieJohnson

Programmer
Apr 16, 2001
2,628
US
I have placed an html "file input" object...

Code:
<input type="file" style="width: 424px" id="GetTheFile">

... on an asp.net (2.0) form to get the name of a file to be used in an event. This all works fine except how do you get the value of the path and filename from the object?

Thanks in advance



ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Either add runat="server" to it so you can access it from your code, or use an asp:FileUpload control. You will then be able to use ControlName.PostedFile.FileName to get the filename.




-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Thanks. I used the runat server and that worked.

I could not find the FileUpload control. Also I thought I saw another post from you saying that if you use that control, the file is uploaded to the server and I don't want that. Just the path and file name to be used in code later.

However, when I use this and click my button to run my event procedure with the code the post back from the update button seems to wipe out the value in the INPUT FILE area. Any thoughts on that?

ProDev, Builders of Affordable Software Applications
Visit me at ==>
May God bless you beyond your imagination!!!
 
Also I thought I saw another post from you saying that if you use that control, the file is uploaded to the server and I don't want that. Just the path and file name to be used in code later.
I'm afraid that's what the FileUpload (it is only available from version 2.0 onwards) and the <input type="file"> will do. You might want to ask in the javascript forum if there is a method to do what you want without uploading the file.

However, when I use this and click my button to run my event procedure with the code the post back from the update button seems to wipe out the value in the INPUT FILE area. Any thoughts on that?
That's the default behaviour of these controls and not a lot you can do about it. You could write the value back out to the control via javascript, but it wouldn't exist is you then looked at the value of the control from the server (so you'd have to duplicate the value in a hidden control as well).


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top