ASP.Net/Response/Write File — различия между версиями

Материал из .Net Framework эксперт
Перейти к: навигация, поиск
м (1 версия)
 
(нет различий)

Версия 15:30, 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>