Asp.net Upload File flashback (modify FileUpload display text, etc.), asp. netfileupload
FileUpload is used to upload files on the asp.net website. However, the "Browse" control cannot be modified. You can use <input type = "file" in html to solve this problem.
First, the page cannot use updatepannel, and then you need to add method = "post" enctype = "multipart/form-data" to the page form"
For example
<form id="form1" runat="server" method="post" enctype="multipart/form-data">
Then place the code at the location required by the page
<input type="text" id="txtPath" name="txt" style="width:250px" runat="server" /> <input type="button" onmousemove="f.style.pixelLeft=event.x-60;f.style.pixelTop=this.offsetTop;" value="Select" size="30" onclick="f.click()" /> <input type="file" id="f" runat="server" onchange="txtPath.value=this.value" accept="image/gif, image/jpeg" name="f" style="position:absolute;filter:alpha(opacity=0);" size="1" hidefocus="true" />
Then write in the upload button event as follows:
1 // obtain the uploaded file from the client 2 HttpPostedFile UserHPF = Request. files ["f"]; 3 // obtain the folder Path 4 string FilePath = Server. mapPath (". /"); 5 string newfilepath = FilePath +" \ "+ System. IO. path. getFileName (UserHPF. fileName); 6 // store the uploaded file in the specified directory. saveAs (newfilepath); 8 9 if (File. exists (newfilepath) 10 {11 WebMessageBox (this, "Import license file successfully! "); 12}
In this way, HttpPostedFile UserHPF = Request. Files ["f"]; the file to be uploaded can be obtained, and then it is the conventional SaveAs.