I want to use StreamWriter to write a file to the temp folder.
It might be a different path on each PC, so I tried using %temp%\\SaveFile.txt
The Path class is very useful here.
You get two methods called
Path.GetTempFileName
Path.GetTempPath
that could solve your issue
So for example you could write: (if you don't mind the exact file name)
using(StreamWriter sw = new StreamWriter(Path.GetTempFileName()))
{
sw.WriteLine("Your error message");
}
Or if you need to set your file name
string myTempFile = Path.Combine(Path.GetTempPath(), "SaveFile.txt");
using(StreamWriter sw = new StreamWriter(myTempFile))
{
sw.WriteLine("Your error message");
}