获取文件名而不上传文件使用FileUpload [英] Get File Name Without Upload File Use FileUpload

查看:142
本文介绍了获取文件名而不上传文件使用FileUpload的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨我需要获取文件名只是没有上传文件..怎么样?

以下代码不起作用,当大文件选择浏览器读取整个文件时如果提交!! !

Hi im Need Get File Name Just Without Upload File..How?
The following code does not work, and when large files have chosen browser to read the entire file if it be submitted !!!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script  runat="server">
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        System.Threading.Thread.Sleep(500)
        Response.Write(FileUpload1.FileName.ToString)
    End Sub
</script>
<html>
<body>
    <form id="Form1"  runat="server" enctype="multipart/form-data">
        <asp:ScriptManager ID="ScriptManager1" runat="server">
        </asp:ScriptManager>
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <br />
                <asp:FileUpload ID="FileUpload1" runat="server" />
                <br />
                <br />
                <asp:Button ID="Button1" runat="server" Text="Get File Name" />
                <br />
                <br />
                <asp:UpdateProgress ID="UpdateProgress1" runat="server">
                    <progresstemplate>
                        Waiting ,,,,</progresstemplate>
                </asp:UpdateProgress>
            </ContentTemplate>
        </asp:UpdatePanel>
    </form>
</body>
</html>

推荐答案

要在服务器端获取所选文件名而不实际上传文件,您必须在客户端上进行一些工作...

1。 FileUpload表示为< input>标记类型属性设置为文件 ...

2.点击后不要将页面发布到服务器但是调用客户端JavaScript方法来提取< input>的值属性。 tag - 这是文件名

3.使用一些AJAX调用发送文件名到服务器

请参阅jsFiddle示例,了解如何在JavaScript中检索所选文件 - http://jsfiddle.net/Ltq5x6bb/ [ ^ ]
To get the selected file name on the server side without actually upload the file you have to do some work on the client...
1. FileUpload is represented as an <input> tag with type attribute set to file...
2. On click do not post the page to the server but call a client-side JavaScript method to extract value attribute of the <input> tag - that's the file name
3. Send file name using some AJAX call to the server
See the jsFiddle sample of how to retrieve the selected file in JavaScript - http://jsfiddle.net/Ltq5x6bb/[^]


这篇关于获取文件名而不上传文件使用FileUpload的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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