Code Snippet posted by:
Poster | Posted on: 6/13/2009 | Category:
C# Codes | Views: 19385 | Status:
[Member]
|
Alert Moderator
To convert Stream object into String, write following code in C#.
Stream stream = GetStream();
byte[] bytes = new byte[stream.Length];
stream.Position = 0;
stream.Read(bytes, 0, (int)stream.Length);
string data = Encoding.ASCII.GetString(bytes); // this is your string
In VB.NET, write following code.
Dim tream As Stream = GetStream()
Dim bytes As Byte() = New Byte(tream.Length) {}
tream.Position = 0
tream.Read(bytes, 0, DirectCast(tream.Length, Integer))
Dim data As String = Encoding.ASCII.GetString(bytes) ' this is your string
You need to use
System.IO and
System.Text namespace to work with above code.