• 20160620001 FileUpload控件获取上传文件的路径


    参考地址: http://bbs.csdn.net/topics/350051517

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

    用js实现

    <%@ 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>
     
    ——————————————————————————————
    后台调用:
    string inputPath = txtFilePath.Value.Trim();
    ——————————————————————————————
     
     
    ——————————————————————————————
    fileupload   有安全机制  无法获得服务器路径。 
     只能通过JS或者修改部分浏览器设置来得到客户端路径。
    ——————————————————————————————
     
     
  • 相关阅读:
    用Python完成一个汇率转换器
    鸿蒙如何用JS开发智能手表App
    鸿蒙如何用JS开发智能手表App
    SAP Spartacus SplitViewComponent Migration 的一个具体例子
    SAP Spartacus B2B 页面 Popover Component 的条件显示逻辑
    SAP Spartacus 升级时关于 schematics 的更新
    SAP Spartacus B2B 页面 Disable 按钮的显示原理
    SAP Spartacus B2B 页面 Disable Confirmation 对话框的显示原理
    通过 Feature Level 动态控制 SAP Spartacus 的页面显示
    SAP Commerce Cloud Build Manifest Components
  • 原文地址:https://www.cnblogs.com/hutie1980/p/5599941.html
Copyright © 2020-2023  润新知