Posted By: Blkbam | Oct 20th, 2005 @ 1:35 PM
page 1 of 1
Comments: 8 | Views: 48269
Blkbam
Blkbam
Bam, Bam! Bam, Bam Bam!
How can I put text in a stream in C#?  Not to sound pushy but nevermind why, I need to pass a stream to a function.  It seems the .Net framework will let me create a stream ie:

Stream s = null;

but it won't let me create and instance of it, ie.

Stream s = new Stream();

I know I can get it from other objects such as a HttpRespone or a Assembly.GetSomethingFromStream.  Any help would be appreciated.

The class you're looking for is StreamWriter
blowdart
blowdart
Peek-a-boo
Blkbam wrote:
Close but no.  StreamWriter/Reader both take either files or other streams.  I need to put the text into a stream without creating a file.


You mean a MemoryStream?
Harlequin
Harlequin
http://twitter.c​om/TrueHarlequin
blowdart wrote:
Blkbam wrote: Close but no.  StreamWriter/Reader both take either files or other streams.  I need to put the text into a stream without creating a file.
You mean a MemoryStream?


That would be a good one, you can put whatever you want into a MemoryStream Smiley
JPrime
JPrime
Manny Calavera

This is off the top of my head, but you should be able to do something like:

string s = "hello world";
MemoryStream m = new MemoryStream(System.Text.Encoding.Default.GetBytes(s));

 

Sven Groot
Sven Groot
My name has 9 letters. Coincidence? I think not...
Blkbam wrote:
Stream s = new Stream();

Stream is an abstract class so it can't be created. You need to create a specific type of stream like a FileStream or a MemoryStream.
CodeMonkey666
CodeMonkey666
Cylons.. Why debugging matters
MemorySteam is one of my most used classes, very handy.
page 1 of 1
Comments: 8 | Views: 48269
Microsoft Communities