This works:
using (StreamWriter stw = new StreamWriter(Server.MapPath("\\xml\\file.xml")))
{
stw.Write(xmlEncStr);
}
This creates an empty file:
using (FileStream file = new FileStream(Server.MapPath("\\xml\\file.xml"), FileMode.CreateNew))
{
using (StreamWriter sw = new StreamWriter(file))
{
sw.Write(xmlEncStr);
}
}
I tried playing around with the FileStream constructor and tried flushing and I still get a zero byte file. The string I am writing is a simple base64 encoded ascii string with no special characters.
I know I can use the first example, but why won't the second work?
Update
This wasn't a Filestream/StreamWriter problem - it was a variable naming problem. I corrected the code above, so now both versions work. I originally had:
StreamWriter strw = new StreamWriter(file)