Yet Another Blog on ASP.NET and Some Other Stuff

Utilize Read-Only TextBoxes in FileUpload Control of ASP.NET

Posted in ASP.NET, C#, Secure Coding, VB.NET, Web Development by Mustafa Basgun on January 28th, 2008

Nowadays, I am spending most of my work time on developing a “document depot” type of web application which has a heavy usage of FileUpload control. And, it was one of the requirements that users should not be able to modify the associated textbox after browsing the document from their hard drives. I believe it is a very good user-experience practice and it avoids some possible security issues as well. After walking around between some search results, I have found the following solution by assuming that FileUpload1 is the ID of the control:

VB.NET:

C#:

As a result, users would be able to select a document only by using the Browse button.

I have tested the sample code with the latest versions of IE and Firefox, and everything seemed to be working fine with both browsers.

3 Responses to 'Utilize Read-Only TextBoxes in FileUpload Control of ASP.NET'

Subscribe to comments with RSS or TrackBack to 'Utilize Read-Only TextBoxes in FileUpload Control of ASP.NET'.

  1. Mark W. said, on January 28th, 2008 at 8:54 pm

    Mustafa - Do you know a way of changing the text on the FileUpload button? Thanks.

  2. Mustafa Basgun said, on January 28th, 2008 at 11:48 pm

    Mark,

    As far as I know, there is no workaround to update the default caption of FileUpload button. It is a read-only property which I guess due to a matter of security. You can try your chance by asking it at the forum (http://forums.asp.net) though.

  3. Bassel Issa said, on February 2nd, 2008 at 9:41 pm

    Hi Mark,

    Check this: http://www.quirksmode.org/dom/inputfile.html

Leave a Reply