I have legacy class that writes some results to a file using StreamWriter, created with constructor that accepts FileStream, which is previously created by giving it’s constructor a file path:
using (FileStream fs = File.Open(outputFilePath, FileMode.Create))
using (StreamWriter sw = new StreamWriter(fs))
{
MyFileWriter.WriteToFile(someData, sw);
}
By the way, stated code is used in WCF service.
Now, I have new requirement where I have to save file to a client file system and I have constraint that I can only send byte[] to client. I would like to make minimal changes to existing code to support this, so is there, for example, some kind of stream which I can create wihtout the need to specify the file path in it’s constructor? Later I would convert this stream to byte[].
I’m open to any other idea you might have, as well.
You can use MemoryStream,