20160620001 fileupload Control gets the path of the uploaded file

Source: Internet
Author: User

Reference Address: http://bbs.csdn.net/topics/350051517

——————————————————————————————

Using JS to achieve

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="BorrowPage.aspx.cs" Inherits="Borrow_BorrowPage" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> < html xmlns = "http://www.w3.org/1999/xhtml" > < head runat = "server" >      < title >xxx上传</ title >          <!--获取文件上传地址-->      < script type = "text/javascript" >      function checkFile()      {          //判断浏览器类型          var isIE = (document.all) ? true : false;          var isIE7 = isIE && (navigator.userAgent.indexOf(‘MSIE 7.0‘) != -1);          var isIE8 = isIE && (navigator.userAgent.indexOf(‘MSIE 8.0‘) != -1);          var file=document.getElementById("UpLoadBorrow");          var path=file.value;          if(isIE7 || isIE8)          {              file.select();              path=document.selection.createRange().text;              document.selection.empty();          }         document.getElementById("txtFilePath").value=path;      }      function checkNull()      {          var path=document.getElementById("txtFilePath").value;         if(path=="" ||path==null)         {          alert(‘请选择要上传的文件!‘);          return false;         }         return true;      }      </ script >      < base target = "_self" /> </ head > < body style = "background-color:#0099FF;" >      < form id = "form1" runat = "server" >      < div style = "margin:0px auto 0px auto;" >          < asp:Image ID = "Image1" runat = "server" BorderStyle = "Double" Width = "750" ImageAlign = "Middle" AlternateText = "上传" />          < br />          上传:< asp:FileUpload ID = "UpLoadBorrow" runat = "server" Height = "22px" onchange = "checkFile()" onkeydown = "event.returnValue=false;" onpaste = "return false" />          < input type = "hidden" id = "txtFilePath" runat = "server" />//这里建立一个隐藏域 用来存地址          < asp:Button ID = "btnUpload" runat = "server" Text = "上传" OnClientClick = "return checkNull()" OnClick = "btnUpLoad_Click" />          < asp:Button ID = "btnBack" runat = "server" Text = "返回" onmousedown = "window.close();" /></ div >      </ form > </ body > </ html >—————————————————————————————— Background Call: string inputPath = txtFilePath.Value.Trim();—————————————————————————————— —————————————————————————————— FileUpload has a security mechanism that cannot obtain a server path. The client path can only be obtained by JS or by modifying some browser settings. ——————————————————————————————

20160620001 fileupload Control gets the path of the uploaded file

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.