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


	SourceXmlMemoryStream.Seek(0, SeekOrigin.Begin);


	SourceXmlMemoryStream.Position = 0

Close Memory Stream


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());


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 mini sites like this. We hope you find the site 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 on this site. If you need help with a problem please use one of the many online forums.