I have an asp uploader and when the user uploads an image it’s displayed, but the user can remove the image, but it’s not removed from Request.Files and then the image will be uploaded. How can I remove it from Request.Files from the javascript??
StepOne.aspx: http://pastebin.com/EUCX783r
StepOne.aspx.cs: http://pastebin.com/aZ3UtV2F
You cannot remove files directly from the FileList as it is readonly. You can remove all of the files within the Files collection by setting it to “” :
But this will not work for individual files.
Suggested Workaround
You can likely handle this by including a hidden input element within your form and monitoring the files that are marked for deletion within this hidden input.
Upon performing your delete (assuming using Javascript), you can add the name of the file to your filesToDelete field (which will be comma-delimited) :
When the uploads are posted to the server, you can specify to only upload those that are not contained within the list of files. Just store the comma-delimited values into a collection and if you prefer, use LINQ to check the collection and compare it to the posted files :
You will just need to include a reference to LINQ at the top of your code-behind page :