Read file into Memory Stream
MemoryStream SourceXmlMemoryStream = new MemoryStream(File.ReadAllBytes(filename));
Write File From Memory Stream
FileStream file = new FileStream(filename, FileMode.Create, FileAccess.Write); //Overwrite the existing file
OutputXmlMemoryStream.WriteTo(file);
file.Close();
OutputXmlMemoryStream.Close();
Seek
SourceXmlMemoryStream.Seek(0, SeekOrigin.Begin);
or
SourceXmlMemoryStream.Position = 0
Close Memory Stream
SourceXmlMemoryStream.Dispose();
Write MemoryStream To File
(Overwrite if alreads exists)
MemoryStream1.Position = 0;
System.IO.File.WriteAllBytes("C:\\_Downloaded\\test1.bin", MemoryStream1.ToArray());
Convert Memory Stream to String
string MyString = Encoding.UTF8.GetString(MyMemoryStream.ToArray());
USEFUL?
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through resources like this. We hope you find it helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support here. If you need help with a problem please use one of the many online forums.