I have the file being used by another process. However I need to be able to save to it using TextWriter (C# .NET). What can I do to get around this?
("The Process cannot access the File error" being thrown on new StreamWriter(filePathName)
XmlSerializer _serializer = new XmlSerializer(typeof(T));
using (TextWriter _writer = new StreamWriter(filePathName))
{
/* [Redacted - internal code] */
_serializer.Serialize(_writer, XMLSettings);
}
As seen above, I need to be able to create a TextWriter and pass that instance into the serializer.
Then the other process is responsible for whether the file is opened exclusively, or whether other processes can read and or write to it. See eg the FileShare flags in FileStream's constructor.