January 2, 2007

Creating A Temp File In The Temporary directory

Use a specific file name in the temporary directory:
private readonly string testPath = 
    Path.Combine(Path.GetTempPath(), "TestSerializer.xml");
Create a temporary file name in the temporary directory but with a specified extension:
public static class PathClassExtender
  public static string GetTempFileName(string newExtension)
    string res = Path.ChangeExtension(Path.GetTempFileName(), newExtension);
    return res;
Sample usage:
string filename = PathClassExtender.GetTempFileName(".bat");
filename will get set to something like

No comments: