Change uploaded file name

Last post 05-16-2008 12:14 AM by nKognito. 1 replies.

Sort Posts:

  • Change uploaded file name

    05-15-2008, 10:54 PM
    • Loading...
    • Dharniuser
    • Joined on 02-05-2008, 9:08 AM
    • Posts 25

    Hi, 

    I used file upload control in one of my apps. I saved all files in one folder (per person) in web server.  Each person has their own folder in web server.

    File name is saved as same as original name. but i heard that, file name cannot be keep as original name for some reasons.

     is it necessary? how abt folder name? need to be changed? what is the best practice?

    apart from security condition, any other reason for it?

    If i want to keep different name what format would u suggest? hashing or date/time format? how abt downloading of file? show original name?

    Thanks!

     

     

     

     

     

  • Re: Change uploaded file name

    05-16-2008, 12:14 AM
    Answer
    • Loading...
    • nKognito
    • Joined on 03-06-2008, 5:11 AM
    • Posts 242

    If you are storing all user's files in specific directory so pay your attention that: user can upload test.zip file twice (user forgot that file has been already uploaded) - in this case depend on your algorithm your application can rewrite the original file or may fall because of adding the file that already exists. So to prevent such case you should generate new file's name (for example by Guid). Here is the scenario: user uploads file, you generate new name using Guid.NewId() method (optionally you can save an old file's name in db) and save it. So if user will upload the same file, you can notify him that file already exists and if he still want to upload it there is no problem.

    May the force be with you
Page 1 of 1 (2 items)