Click here to Skip to main content
15,881,864 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Please how i can convert memorystream to steam ?
Posted
Comments
sjelen 25-Sep-12 7:13am    
MemoryStream is a Stream. What do you mean by 'convert'?
phil.o 20-May-16 9:48am    
If it were possible, we could use MemoryStreams to move trains and boats ; which, as far as I know, is not yet implemented.

Assuming you mean "Stream" instead of "Steam":

"Please how i can convert memorystream to stream ?"

You don't have to. A MemoryStream is derived from Stream, which means it is one already.
Anything which expects a Stream will accept a MemoryStream instead.

C#
MemoryStream myMemoryStream = new MemoryStream();
Stream myStream = myMemoryStream;
 
Share this answer
 
Use Stream.CopyTo Method(.Net 4 and above)
Eg:
http://msdn.microsoft.com/en-us/library/dd782932.aspx[^]

(.Net 3.5 and before)
C#
public static void CopyStream(Stream input, Stream output)
{
    byte[] buffer = new byte[32768];
    int read;
    while ((read = input.Read(buffer, 0, buffer.Length)) > 0)
    {
        output.Write (buffer, 0, read);
    }
}
 
Share this answer
 
v2
Comments
sjelen 25-Sep-12 7:14am    
This is copying from one stream to another, not 'converting'
Kuthuparakkal 25-Sep-12 7:16am    
poor fellow, doesnt know the basics!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900