Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to create Stream from String?

Status
Not open for further replies.

vladibo

Programmer
Sep 14, 2003
161
CA
How to create Stream from String?
 
not sure what you mean
Code:
public static void CreateFile()
{
	string str = "test string to stream";
	MainClass.WriteOutput(str);
}

public static void WriteOutput(string str) 
{
	string path = @"C:\marty\CSharp\textfile.txt";
	using (StreamWriter stw = new StreamWriter(path)) 
	{
		try
		{
			stw.WriteLine(str);			
		} 
		catch (Exception e)
		{
			Console.WriteLine(e.Message);
		}
	}
}
hth,
Marty
 
Thanks Marty, but I don't want to work with files. May be MemoryStream?
 
Interesting question - could you write text to a memory stream and print the contents of this stream ?
Without savng the file first ?
Steve
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top