How can I create a temp file with a specific extension with .NET?

后端 未结 17 2047
北恋
北恋 2020-11-28 01:49

I need to generate a unique temporary file with a .csv extension.

What I do right now is

string filename = System.IO.Path.GetTempFileName().Replace(         


        
17条回答
  •  眼角桃花
    2020-11-28 02:11

    The MSDN documentation for C++'s GetTempFileName discusses your concern and answers it:

    GetTempFileName is not able to guarantee that the file name is unique.

    Only the lower 16 bits of the uUnique parameter are used. This limits GetTempFileName to a maximum of 65,535 unique file names if the lpPathName and lpPrefixString parameters remain the same.

    Due to the algorithm used to generate file names, GetTempFileName can perform poorly when creating a large number of files with the same prefix. In such cases, it is recommended that you construct unique file names based on GUIDs.

提交回复
热议问题