.

c# working with temp files

the following will create a random filename for you

var tempPath = Path.GetTempPath();
var randomFileName = Path.GetRandomFileName();
var fileNameWithoutExtension = Path.GetFileNameWithoutExtension(randomFileName);
var myFileName = fileNameWithoutExtension + ".xml";
var myFullFileName = Path.Combine(tempPath, myFileName);

//create the file if needed
using (TextWriter writer = File.CreateText(myFullFileName))
{
    writer.Write("this is my temp file");
}

What's your thoughts on this?

*

Protected by WP Anti Spam