如何在C#中将字符串写入response.outputstream [英] how to write string to response.outputstream in c#
本文介绍了如何在C#中将字符串写入response.outputstream的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在ASP.net页中使用response.OutputStream,
此页面将返回字符串值,
我想将此字符串值放入response.OutputStream
请怎么做
Thanks
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
推荐答案
Response.OutputStream
返回System.IO.Stream
的对象.
看看下面的链接.
http://msdn.microsoft.com/en-us/library/system. web.httpresponse.outputstream.aspx
您可以按以下方式将System.IO.Stream
的对象转换为String
.
Response.OutputStream
returns object ofSystem.IO.Stream
.
Have a look at below link.
http://msdn.microsoft.com/en-us/library/system.web.httpresponse.outputstream.aspx
You may convert object ofSystem.IO.Stream
toString
as below.
using (StreamReader reader = new StreamReader(yourStream))
{
string myString = reader.ReadToEnd();
}
已更新-答案已根据您在解决方案1中发布的评论进行了更新.
Updated - Answer Updated based on your comment posted in Solution-1.
string s = "YourString";
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(s);
Response.OutputStream.Write(bytes, 0, bytes.Length);
您可以使用OutputStream.Write缓冲区,偏移量和计数作为参数的方法.
You can use OutputStream.Write method with buffer, offset and count as arguments.
HttpResponse.OutputStream属性的类型为System.IO.Stream
System.IO.Stream内置了ToString方法,用于将当前对象转换为字符串内容.因此,您可以将代码编写为:
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:
myResponse.OutputStream.ToString()
这篇关于如何在C#中将字符串写入response.outputstream的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文