Click here to Skip to main content
15,867,488 members
Please Sign up or sign in to vote.
2.67/5 (3 votes)
See more:
Is there any 2-3 line simple way to do this?
Thanks.
Posted

byte[] byteArray = Encoding.ASCII.GetBytes( test );
MemoryStream stream = new MemoryStream( byteArray );
 
Share this answer
 
Comments
LighthouseCall 21-Mar-11 10:42am    
Yes I did find this when I researched it a bit.
But when I tried to call "test" I was still getting an error saying cannot convert from string to stream..
Maybe it isn't test i have to call?
Piccadilly Yum Yum 21-Mar-11 10:45am    
have you declared variable 'test' ?
LighthouseCall 21-Mar-11 11:52am    
Yes of course..
C#
byte[] byteArray = Encoding.ASCII.GetBytes(test); 
MemoryStream stream = new MemoryStream(byteArray);


You could have found this with google.

EDIT ==================

C#
string test = "My test string.";
byte[] byteArray = Encoding.ASCII.GetBytes(test); 
MemoryStream stream = new MemoryStream(byteArray);


It works just fine for me. (using .Net 4.0, but it should be good for any version of .Net).
 
Share this answer
 
v4
Comments
LighthouseCall 21-Mar-11 10:41am    
Yes I did find this when I researched it a bit.
But when I tried to call "test" I was still getting an error saying cannot convert from string to stream..
Maybe it isn't test i have to call?
#realJSOP 21-Mar-11 12:42pm    
The variables that I used are not necessarily going to be the same ones you use.
#realJSOP 21-Mar-11 12:46pm    
I edited my answer to include the declaration/initialization of "test", and it worked fine for me.
string value = "Hello World";
System.IO.StringReader reader = new System.IO.StringReader(value);

by avigdose:
http://www.codeproject.com/script/Membership/View.aspx?mid=1909728[^]
 
Share this answer
 

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