I’ve got an asp:FileUpload control to upload images to my server, which is local.
It works well, however I decided to test what would happen if users upload an image which has the same file name as an existing image on the server. The result is that the original image is overwritten by the new one.
I thought of writing some code which would append a number at the end of the filename if the respective file already exists, however I believe that this is a bit flawed as a user may still be able to provide a file name with a number appended, thus still overwriting.
What would be the best approach to solve this problem?
You can use a Globally Unique IDentifier to ensure that each file name is unique. If you want to preserve the original file name, you can prefix it with a GUID.