McKelt.com

Remembering Thoughts

 

Recent comments

Authors

Categories


Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

© Copyright 2010

Stream bytes to files

                using (var stream =
                    Assembly.GetAssembly(typeof(StubPolicy)).GetManifestResourceStream(
                        "Documents.TestHelpers.Files.test.msg"))
                {
                    const int bufferLength = 256;
                    var buffer = new Byte[bufferLength];
                    if (stream != null)
                    {
                        int bytesRead = stream.Read(buffer, 0, bufferLength);

                        using (var fs = new FileStream(filename, FileMode.CreateNew, FileAccess.Write))
                        {
                            // Write out the input stream
                            while (bytesRead > 0)
                            {
                                fs.Write(buffer, 0, bytesRead);
                                bytesRead = stream.Read(buffer, 0, bufferLength);
                            }
                            fs.Close();
                        }
                        stream.Close();
                    }
                }

Posted by chris on Wednesday, February 10, 2010 3:48 PM
Permalink | Comments (0) | Post RSSRSS comment feed

Add comment


(Will show your Gravatar icon)

  Country flag

biuquote
  • Comment
  • Preview
Loading