1<%@ CodeTemplate Language="C#" TargetLanguage="Text" Description="AddTextWriter Demonstration." %>
2<%@ Import Namespace="System.IO" %>
3This template demonstrates using the AddTextWriter method
4to output the template results to multiple locations concurrently.
5<script runat="template">
6public override void Render(TextWriter writer)
7{
8 StreamWriter fileWriter1 = new StreamWriter(@"C:\test1.txt", true);
9 this.Response.AddTextWriter(fileWriter1);
10
11 StreamWriter fileWriter2 = new StreamWriter(@"C:\test2.txt", true);
12 this.Response.AddTextWriter(fileWriter2);
13
14 base.Render(writer);
15
16 fileWriter1.Close();
17 fileWriter2.Close();
18}
19</script>
2<%@ Import Namespace="System.IO" %>
3This template demonstrates using the AddTextWriter method
4to output the template results to multiple locations concurrently.
5<script runat="template">
6public override void Render(TextWriter writer)
7{
8 StreamWriter fileWriter1 = new StreamWriter(@"C:\test1.txt", true);
9 this.Response.AddTextWriter(fileWriter1);
10
11 StreamWriter fileWriter2 = new StreamWriter(@"C:\test2.txt", true);
12 this.Response.AddTextWriter(fileWriter2);
13
14 base.Render(writer);
15
16 fileWriter1.Close();
17 fileWriter2.Close();
18}
19</script>
以访问TextWriter,也就是说你也可以直接添加其它的附属信息到模版输出的内容中。