Click here to Skip to main content
15,912,897 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
Hi,

I am using response.OutputStream in ASP.net page,
this page will return string value,
and i want put this string value in response.OutputStream

How to do that please

thanks
Posted
Updated 30-Oct-11 19:00pm
v2

You can use OutputStream.Write method with buffer, offset and count as arguments.
 
Share this answer
 
Response.OutputStream returns object of System.IO.Stream.

Have a look at below link.
http://msdn.microsoft.com/en-us/library/system.web.httpresponse.outputstream.aspx

You may convert object of System.IO.Stream to String as below.
C#
using (StreamReader reader = new StreamReader(yourStream))
{
  string myString = reader.ReadToEnd();
}


Updated - Answer Updated based on your comment posted in Solution-1.
C#
string s = "YourString";
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s);

Response.OutputStream.Write(bytes, 0, bytes.Length);
 
Share this answer
 
v2
Comments
MrLonely_2 31-Oct-11 4:06am    
Thanks man,
but i want to use Response.OutputStream as i want to use AJAX,
but it not worked for me,
Can you tell me how to enable AJAX in my ASP.net project please.
I want clear way to do that
thank again
RaisKazi 31-Oct-11 5:08am    
Welcome. :)
Have a look at my below Tip/Trick Article on "Asp.Net Ajax".
http://www.codeproject.com/Tips/224406/Simplifying-Asp-Net-Core-Ajax
HttpResponse.OutputStream property is of type System.IO.Stream

System.IO.Stream has built in ToString method to convert the current object into string content. So, you can write the code as:

C#
myResponse.OutputStream.ToString()
 
Share this answer
 
Comments
MrLonely_2 31-Oct-11 1:01am    
Thanks man,
but i want to pass the string to the OutputStream
RaisKazi 31-Oct-11 1:06am    
My 5!. This is an easier way than what I proposed. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900