StreamWriter throws "The filename, directory name, or volume label syntax is incorrect" on a path with DateTime

Advertisements Initially I was using just TextWriter iterationLogger = new StreamWriter(Iteration log.txt"); which works fine, but I wanted to add a timestamp to the file and tried this: TextWriter iterationLogger = new StreamWriter($"{DateTime.Now} Iteration log.txt"); Then StremWritter throws "The filename, directory name, or volume label syntax is incorrect" I tried various arguments (append, encoding, @,… Read More StreamWriter throws "The filename, directory name, or volume label syntax is incorrect" on a path with DateTime

How can i create a new file using FileStream without overwriting existing?

Advertisements I am creating an xml file using the following: string filename = string.Format("MyXMLFile{0}-{1}", Id, Name); try { FileStream fs = new FileStream(filename + ".xml", FileMode.Create); using (XmlTextWriter writer = new XmlTextWriter(fs, new UTF8Encoding())) { //write xml data here } } catch (exception ex) { } The issue is that this code is called from… Read More How can i create a new file using FileStream without overwriting existing?