I have a stream saved to a file the following way:
public void SaveTest(DataObject data)
{
var fullPath = Path.Combine(Path.GetTempPath(), data.Descriptor.Name);
var fileStream = new FileStream(Path.Combine(fullPath, ".content"), FileMode.CreateNew);
data.Content.CopyTo(fileStream);
fileStream.Close();
var information = new XElement("Test Information",
new XAttribute("Name", data.Descriptor.Name),
new XAttribute("Description", data.Descriptor.Description),
new XAttribute("Owner", data.Descriptor.Owner)
);
information.Save(Path.Combine(fullPath, ".information"));
}
DataObject contains a stream which is the test’s content and a descriptor with 3 fields I’d like to save.
Now I need a method to read those files, and I need to read the .content file as a stream, not string. How can I do that?
Well, you can open it as a stream as simply as:
Or you can read the whole lot as a byte array:
(You can then wrap that in a
MemoryStreamif you want.)