In .NET 4, you can use Stream.CopyTo to copy a stream, instead of the home-brew methods listed in the other answers.
MemoryStream _ms;
public MyClass(Stream sourceStream)
_ms = new MemoryStream();
sourceStream.CopyTo(_ms);
}
More Related Contents:
- Is there a way to check if a file is in use?
- What’s the fastest way to read a text file line-by-line?
- How do I save a stream to a file in C#?
- Easiest way to read from and write to files
- Reading large text files with streams in C#
- How can I read a file even when getting an “in use by another process” exception?
- How do I create an Excel (.XLS and .XLSX) file in C# without installing Microsoft Office?
- Creating application shortcut in a directory
- Save and load MemoryStream to/from a file
- Validate image from file in C#
- How do I convert struct System.Byte byte[] to a System.IO.Stream object in C#?
- Is a memory leak created if a MemoryStream in .NET is not closed?
- “The given path’s format is not supported.”
- Stream.Seek(0, SeekOrigin.Begin) or Position = 0
- How do I concatenate two System.IO.Stream instances into one?
- An elegant way to consume (all bytes of a) BinaryReader?
- What is the difference between StreamWriter.Flush() and StreamWriter.Close()?
- HttpWebRequest & Native GZip Compression
- How to get the location of the DLL currently executing?
- Image.FromStream() method returns Invalid Argument exception
- Is there a faster way than this to find all the files in a directory and all sub directories?
- MemoryStream – Cannot access a closed Stream
- Error” Parameter is not valid ” while converting Bytes into Image
- How do I get the directory from a file’s full path?
- When or if to Dispose HttpResponseMessage when calling ReadAsStreamAsync?
- How to read last “n” lines of log file [duplicate]
- Memorystream.Read() always returns 0 bytesRead with empty byte[]
- Quickest way in C# to find a file in a directory with over 20,000 files
- how to handle spaces in file path if the folder contains the space?
- How can I split (copy) a Stream in .NET?