ASP.Net/Response/Write File
Содержание
Read data from text file (C#)
<source lang="csharp">
<%@ Page Language="C#" %> <html> <head>
<title>Simple ASP.NET Page</title>
</head> <body> <% System.IO.StreamReader sr = new System.IO.StreamReader("/file.txt"); string line; while(sr.Peek() != -1) {
line = sr.ReadLine(); Response.Write(Server.HtmlEncode(line) + "
");
} %> </body> </html>
</source>
Read file and display its content on the page (VB.net)
<source lang="csharp">
<%@ Page Language="VB" %> <html>
<body>
Response.WriteFile()
<% Dim filename As String filename = "file.txt" Response.WriteFile(filename) %> </body>
</html> <%--
--%>
</source>
Write file (C#)
<source lang="csharp">
<%@ Page Language="c#" %> <html>
<body>
Response.WriteFile()
<%; string FileName; //make sure the text file is in the correct place. FileName = "file.txt"; Response.WriteFile(FileName); %> </body>
</html>
</source>
Writing a file to output (VB.net)
<source lang="csharp">
<%@ Page Language="vb" %> <html>
<head> <title>Writing a file to output in ASP.NET</title> <script runat="server"> Sub Page_Load() Response.WriteFile(MapPath("file.txt")) End Sub </script> </head>
<body>
<asp:label id="Message" runat="server"/>
</body> </html>
</source>