1

Not sure why I can't seem to update a value. I'm using a file uploader and I need to append an invoice number to the file name, so we don't get duplicate files.

Here is the code:

console.log(data.files[0]);
            console.log(data.files[0].name);
            console.log('$("#InvoiceNumber").val() =' + $("#InvoiceNumber").val() + "-" + data.files[0]['name']);
            //here I try to update 
            data.files[0]['name'].value = $("#InvoiceNumber").val() + data.files[0]['name'];
            //have also tried
            // data.files[0]['name'] = $("#InvoiceNumber").val() + data.files[0]['name'];
            //and
            //data.files[0].name = $("#InvoiceNumber").val() + data.files[0].name;

            console.log(data.files[0]);

The results from outputting to console are.

enter image description here

I can't change the file name server side, as duplicates exist. Anyone know why I can't update that value. Thanks

1
  • 1
    You'll have to do that at the server. Commented Mar 21, 2019 at 23:14

1 Answer 1

5

File#name property is readonly. There is nothing you can do with it.

Sign up to request clarification or add additional context in comments.

2 Comments

Oh ok so that must be why, gee this makes my life much harder :( Thanks for the help
For those that are interested, I solved my problem. When my form is submitted, I grab the file name which was returned from the file upload funciton. Then I appended my invoice number to the file name and use System.IO.File.Move("oldfilepath+oldfileName", "newfilepath+newfileName"); to rename the file. Then save against the model. Thanks all for your help :)

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.