Click here to Skip to main content
15,891,649 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
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 !!!
HTML
<!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>
Posted
Updated 14-Dec-14 8:02am
v2
Comments
Zoltán Zörgő 14-Dec-14 13:45pm    
Please, format your code, tag your post properly, and ask an intelligible question. What does it mean "file name without upload file"? It makes no sense.

1 solution

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/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900