tags:

views:

29

answers:

1

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.

+2  A: 

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()

Jesper Palm
I would use `Path.GetRandomFileName` rather than `Guid.NewGuid`, but good answer otherwise ;)
Thomas Levesque