locked
How to change the text with new text in Javacript RRS feed

  • Question

  • User-1355965324 posted

    I am  getting the file name  using  Input file, then how can I  replace the  selected filename  with new file as <Selected Filename> +'_'+CurrentDate+extension of the selected file in javascript. and the new file name  should be  stored in the  input text NewFileName, Please help

     <div class="col-md-6 ">
                                        <div class="form-group">
                                            <label asp-for="FileNameURL" class="control-label control-label-left col-sm-3 text-danger">File Name</label>
                                            <div class="col-sm-9">
                                                <div class="custom-file">
                                                    <input type="file" id="FileNameURL" name="FileNameURL" class="form-control custom-file-input">
                                                    <span class="input-group-btn">
                                                    </span>
                                                </div>
                                            </div>
    
                                        </div>
    
                                    </div>
    
                                    <div class="col-md-6">
                                        <div class="form-group">
                                                
                                                    <label asp-for="NewFileName" class="control-label control-label-left col-sm-3 text-danger">New File Name</label>
                                                    <div class="controls col-sm-9">
                                                        <input id="NewFile" asp-for="NewFileName" class="form-control"  />
                                                        <span asp-validation-for="NewFileName" class="text-danger">@ViewBag.ErrorDescription</span>
                                                    </div>
                                                
                                        </div>
    
                                    </div>
    
     $('.custom-file-input').on("change", function () {
                var fileName = $(this).val().split("\\").pop();
                $('#NewFile').val(filenamepart+'_'+Date(ddmmyyyy)+entension); //  I want to add date after the selected filename
    
            });
    
    

    Thursday, February 6, 2020 10:46 AM

Answers

  • User711641945 posted

    Hi polachan,

    For add date to the Name,you could follow:

    var today = new Date();
    var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
    $('#NewFile').val(filenamepart+ '_' + date + entension);

    Best Regards,

    Rena

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 7, 2020 8:43 AM

All replies

  • User-474980206 posted

    no can do. the browser security prevents setting the file name via code. you should rename on the server.

    Thursday, February 6, 2020 4:38 PM
  • User711641945 posted

    Hi polachan,

    For add date to the Name,you could follow:

    var today = new Date();
    var date = today.getFullYear() + '-' + (today.getMonth() + 1) + '-' + today.getDate();
    $('#NewFile').val(filenamepart+ '_' + date + entension);

    Best Regards,

    Rena

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Friday, February 7, 2020 8:43 AM