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

后端 未结 17 2027
北恋
北恋 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:14

    You can also do the following

    string filename = Path.ChangeExtension(Path.GetTempFileName(), ".csv");
    

    and this also works as expected

    string filename = Path.ChangeExtension(Path.GetTempPath() + Guid.NewGuid().ToString(), ".csv");
    

提交回复
热议问题