For training related to .net,OOPS,design patterns, MVC,WCF and .net fundamentals
contact at sukeshmarla@gmail.com or Click Here

20 April 2011

Convert String to Stream and stream to string


using System.IO;
using System.Text;
using System;
namespace CustomIoClasses
{
class ClsStream
{
public static string GetString(Stream ObjPriReader)
{
return new StreamReader(ObjPriReader).ReadToEnd();
}
public static Stream GetStream(String StrPriData)
{
byte[] byteArray = Encoding.ASCII.GetBytes(StrPriData);
MemoryStream stream = new MemoryStream(byteArray);
return stream;
}
static void Main(string[] args)
{
string str = "I love my India";
System.Console.WriteLine(GetString(GetStream(str)));
Console.ReadKey();

}
}
}