Unique file names: prevent overwriting files in TargetFolder

3 posts, 0 answers
  1. Mike
    Mike avatar
    22 posts
    Member since:
    Jul 2008

    Posted 30 Jan 2015 Link to this post

    When a file gets uploaded to the temporary folder its name is changed to ensure that it is unique. However the file gets copied to the TargetFolder with its original name. If two people upload files with the same name at the same time then the latter will overwrite the former. How can I ensure that each file in the TargetFolder will be unique so as to prevent collisions?
    SANJAY avatar
    61 posts
    Member since:
    Jun 2012

    Posted 31 Jan 2015 in reply to Mike Link to this post

    Hi Mike

    I would like to bring forward two options

    1) Can rename the file by appending the count of file to the name of the file. Eg if the original name is sample.txt then for the first file rename to 1sample.txt . So every time a file is uploaded the count would give a unique name
    2) rename the file with new guid string. Problems with is are
         a) Long names
         b) The loss of name may not be able to identify the content of files

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Mike
    Mike avatar
    22 posts
    Member since:
    Jul 2008

    Posted 02 Feb 2015 in reply to SANJAY Link to this post

    Thanks. I hadn't been able to figure out how to rename the file but I finally found this post.
Back to Top