locked
List Of Files RRS feed

  • Question

  • User-1499457942 posted

    Hi

      I have below code and i want List of files also gets displayed which user have selected for Uploading before click on Upload Button

    <asp:FileUpload runat="server" ID="FileUpload1" AllowMultiple="true" />

    Thanks

    Wednesday, December 19, 2018 7:03 AM

Answers

  • User-1174608757 posted

    Hi JagjitSingh,

      According to your description ,I have made a sample here.I suggest you to use Jquery to accomplish your requirement.

     You could loop the filename of items you selected in function .change() of Fileupload control.Here is the code,I hope it can help you.

    Fileupload.aspx:

    <head runat="server">
        <title></title>
        <script src="../Scripts/jquery-3.3.1.js"></script>
        <script>
                    $(function () {
                        $('#FileUpload1').change(function () {
                            var fp = $("#FileUpload1");
                            var lg = fp[0].files.length;
                            var items = fp[0].files;
                            if (lg > 0)
                            {
                                for (var i = 0; i < lg; i++) {
                                    var fileName = items[i].name;
                                    $("#ulList").append("<li>" + fileName + "</li>");
                                }
                            }
                         })
                     }) 
        </script>
    
    </head>
    <body>
        <form id="form1" runat="server">
            <div>
               
                <asp:FileUpload ID="FileUpload1" runat="server" AllowMultiple="true" />
                <ul id="ulList"></ul>
            </div>
        </form>
    </body>

    It shows as below:

    Best Regards

    Wei Zhang

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, December 20, 2018 4:50 AM