Asp.net Upload File flashback (modify FileUpload display text, etc.), asp. netfileupload

Source: Internet
Author: User

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.

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.