Display only file name in FileUpload control
I have a webpage in asp.net 3.5 that uses the FileUpload control. When a user clicks on the "Browse" button (which is part of the control) the control displays a file select popup (dialog box). When the user selects the file which they wish to upload, by default the full path to the file is shown in the textbox (which is also part of the control); however, I wish for it to only display the file name and not the full path.开发者_开发百科 Anyone know of a slick and easy way to do this?
I'm pretty sure that isn't possible. You cannot set the value inside of the FileUpload control's textbox at anytime, via server side or client side script.
The FileUpload control is essentially an html <input type="file">
As such, the browser determines how to render it. You have no control over this.
As others have said, the native file input control won't do this. You may be able to work around that with some overlaid styling of the control, however. Start here. It'll likely take a little bit of JavaScript to break out the file name from the path, display only the latter (in the custom non-control elements), but use both when it matters (in the control itself). But it should be doable.
精彩评论