Way to get unique filename if specified filename already exists (.NET)

前端 未结 4 1315
醉酒成梦
醉酒成梦 2021-01-20 00:00

Is there a built in .NET function to get a unique filename if a filename already exists? So if I try and save MyDoc.doc and it already exists, the file will sav

4条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-20 00:39

    As the other answers shows, there are multiple ways of doing this, but one thing to be aware of is if other processes than your can create files you have to be careful, since if you check that a filename is available, by the time you save your new file, some other process might already have saved a file using that name and you'll overwrite that file.

提交回复
热议问题