Chris McKelt

Remembering Thoughts

 

Recent comments

Archive

Authors

Categories

None


Disclaimer

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

© Copyright 2012

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 6:48 AM
Permalink | Comments (5) | Post RSSRSS comment feed

Comments (5) -

purple black United States

Wednesday, April 13, 2011 8:26 PM

purple black

Thank you for a great post.

article submission service United States

Thursday, April 14, 2011 7:13 AM

article submission service

Good points

low residue diet United States

Thursday, April 14, 2011 8:10 AM

low residue diet

I never thought of it that way, well put!

incorporate online United States

Thursday, April 14, 2011 8:43 AM

incorporate online

I agree 100%

floor sander brisbane United States

Thursday, April 14, 2011 8:58 AM

floor sander brisbane

Right on!