ASP.Net/Response/Write File — различия между версиями
Admin (обсуждение | вклад) м (1 версия) |
|
(нет различий)
|
Текущая версия на 11:54, 26 мая 2010
Содержание
Read data from text file (C#)
<%@ 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) + "<br/>");
}
%>
</body>
</html>
Read file and display its content on the page (VB.net)
<%@ Page Language="VB" %>
<html>
<body>
<H2>Response.WriteFile()</H2>
<%
Dim filename As String
filename = "file.txt"
Response.WriteFile(filename)
%>
</body>
</html>
<%--
--%>
Write file (C#)
<%@ Page Language="c#" %>
<html>
<body>
<H2>Response.WriteFile()</H2>
<%;
string FileName;
//make sure the text file is in the correct place.
FileName = "file.txt";
Response.WriteFile(FileName);
%>
</body>
</html>
Writing a file to output (VB.net)
<%@ 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>