如何提交不提交文件本身在ASP.NET文件的原始路径和文件名? [英] How to submit a file's original path and filename without submitting the file itself in ASP.NET?

查看:173
本文介绍了如何提交不提交文件本身在ASP.NET文件的原始路径和文件名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我怎么能有一个ASP.NET形式的文件浏览为文件上传控制确实在控制,但不是submmitting整个文件,只提交路径从巫文件是从(与原来的文件名)发现了什么?

How can I have a control on a ASP.NET form that browses for files as FileUpload control does, but instead of submmitting the whole file, it only submits the path from witch the file was found from (with the original file name)?

推荐答案

下面是一种变通方法我按照下面的论坛帖子的说明进行:的 http://forums.asp.net/p/1189182/2040139.aspx#2040048

Here is a workaround I made by following the instructions of the following forum post: http://forums.asp.net/p/1189182/2040139.aspx#2040048

<asp:FileUpload ID="File1" runat="server" onchange="GetFileName();"/> 
<asp:Button ID="Submit" runat="server" Text="Submit" OnClientClick="DisableFileSelector();" />
<asp:HiddenField id="txtFileName" runat="server" />

<script language="javascript" type="text/javascript">
    function GetFileName()
    {
        document.getElementById('<%=txtFileName.ClientID %>').value = document.getElementById('<%=File1.ClientID %>').value;
    }
    function DisableFileSelector() {
        document.getElementById('<%=File1.ClientID %>').disabled = true;
    }
</script>

当然,这仅在启用JavaScript的工作。如果禁用JavaScript,表单将提交的文件,但你仍然可以在第一次使用前添加以下code持之以恒的网站的功能 txtFileName 是被使用。

if (File1.HasFile)
{
    txtFileName.Value = File1.PostedFile.FileName;
}

这篇关于如何提交不提交文件本身在ASP.NET文件的原始路径和文件名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆