user34537
user34537

Reputation:

Temp Filename on specific partition?

I know about Path.GetTempFileName() and how to get the temp folder (usually its on your C drive)

But how do i get a temp filename on a specific partition? i think as a workaround i'll do something like targetBaseDir/temp.tmp and then File.Move when its complete.

Upvotes: 1

Views: 120

Answers (1)

Jesper Palm
Jesper Palm

Reputation: 7248

Why not just create your own GetTempFilePath method?

Something like this

string GetTempFilePath(string basePath, string extension)
{
    return Path.Combine(basePath, Guid.NewGuid().ToString()+"."+extension);
}

//Usage
GetTempFilePath("E:\\", "tmp");

//Output
//E:\e2e4873e-daf5-41b6-bdc5-2afec61921e2.tmp

Or you can use the native GetTempFileName method that is used by System.IO.Path.GetTempFileName()

Upvotes: 2

Related Questions