ASP.Net/File Directory/File Read

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

Read file to the end

   <source lang="csharp">

<%@ Page Language="vb" %> <html>

  <head>
     <title>Unload event example</title>
     <script runat="server">
        Dim TheFile As System.IO.StreamReader
        Sub Page_Load()
           TheFile = System.IO.File.OpenText(MapPath("file.txt"))
Message.Text = "
" & _
               Server.HtmlEncode(TheFile.ReadToEnd()) & "
"
        End Sub
        Sub Page_Unload()
           TheFile.Close()
        End Sub
     </script>
  </head>

<body>

  <asp:label id="Message" runat="server"/>

</body> </html>

      </source>