Jasinski Technical Wiki

Navigation

Home Page
Index
All Pages

Quick Search
»
Advanced Search »

Contributor Links

Create a new Page
Administration
File Management
Login/Logout
Your Profile

Other Wiki Sections

Software

PoweredBy

Streams - .NET Framework

RSS
Modified on Wed, Apr 04, 2012, 12:39 PM by Administrator Categorized as ·Net Framework

Reading a String into a Memory Stream

var contents = "Hello world";
var ms = new MemoryStream(ASCIIEncoding.Default.GetBytes(contents));

Reading a File into a Memory Stream

var fi = new FileInfo(sourceFile);
using (var fs = fi.OpenRead())
{
    using (var ms = new MemoryStream())
    {
        ms.SetLength(fs.Length);
        fs.Read(ms.GetBuffer(), 0, (int)fs.Length);
        ms.Flush();
        fs.Close();

        // Do something here with the memory stream
    }
}

ScrewTurn Wiki version 3.0.1.400. Some of the icons created by FamFamFam. Except where noted, all contents Copyright © 1999-2024, Patrick Jasinski.