Utilize Read-Only TextBoxes in FileUpload Control of ASP.NET
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.
Mustafa – Do you know a way of changing the text on the FileUpload button? Thanks.
Mark W.
January 28, 2008 at 8:54 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.
Mustafa Basgun
January 28, 2008 at 11:48 PM
Hi Mark,
Check this: http://www.quirksmode.org/dom/inputfile.html
Bassel Issa
February 2, 2008 at 9:41 PM
What about the problem of copy and paste text with the mouse?
Supertorpe
July 16, 2008 at 7:05 AM
Good article.
Abhiram Reddy Mekha
September 16, 2008 at 10:25 AM
How can we change the text inside the FileUpload control as normally we do?
Ex: textbox1.text = “file.lio”
Saravana
November 15, 2008 at 4:57 AM
I want to ask the same question as Supertorpe.
What about mouse copy and paste?
Brenda
November 28, 2008 at 12:59 PM
It seems like it would be better/easier to just add the following attribute:
<asp:FileUpload id=”FileUpload1″ runat=”server” ContentEditable=”false” />
It does what you want, works in IE and Firefox, and prevents the copy and paste issue others mentioned.
Danny
December 5, 2008 at 9:12 AM
Excellent article!
Senthil Kumar
February 13, 2009 at 4:20 AM