Search
Submit & Win
Submit and win
Cash Prizes !
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Codes Author
Mon, 22-Dec-2014 Authors
Sheonarayan
40
All Time Authors
Satyapriyanayak
12160
Vishal@Neeraj
10880
Jayakumars
8120

Latest members | More ...


(Statistics delayed by 5 minutes)
 Codes

How to convert Stream into String?

Poster
Posted by Poster under C# on 6/13/2009 8:33:30 AM | Views : 42421 | Status : [Member]

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.


Share this to:

Bookmark It

Comments or Responses


Login to post response