default.aspx

来自「Professional ASP.NET source code」· ASPX 代码 · 共 66 行

ASPX
66
字号
<%@ Page Trace="false" Language="C#" debug="true" %>

<%@ Import Namespace="System.Text" %>
<%@ Import Namespace="System.IO" %>

<H2>TextWriter</H2>

<script runat=server>

	protected void WriteContentsToResponse( TextReader r )
	{
		string line;

		line = r.ReadLine();

		while ( line != null )
		{
			Response.Write(line);
			Response.Write( "<BR>" );
			line = r.ReadLine();
		}

	}

</script>


<%

TextWriter tw;

// Uncomment this to remove error (shows you can not create text writer class)
//tw = new TextWriter();



%>
<H3>Reading a String using TextReader</H3>
<P>The following lines are read from a string using StringReader :<BR><BR>

<%
	string text;

	text = "A\nString\nContaining\nMultiple\nLines";
	WriteContentsToResponse( new StringReader(text) );
%>

<H3>Reading a File using TextReader</H3>
<P>The following lines are reader from a file using File using StreamReader :<BR><BR>

<%
	string fileToRead;
	StreamReader sr;


	fileToRead = Server.MapPath("myfile.txt" );

	sr = File.OpenText( fileToRead );

	WriteContentsToResponse(sr);
	sr.Close();
	

%>

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?