ASP.Net/Server/Map Path

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

MapPath(file) (VB.net)

   <source lang="csharp">

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

  <head>
     <title>MapPath method example</title>
     <script runat="server">
        Sub Page_Load()
           Message.Text = MapPath("global.asax")
        End Sub
     </script>
  </head>

<body>

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

</body> </html>

      </source>
   
  


Showing ServerVariable values via the ServerVariables Collection in ASP.NET

   <source lang="csharp">

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

  <head>
     <title>Showing ServerVariable values via the ServerVariables Collection in ASP.NET</title>
  </head>

<body>

<%

   Dim VirPath, PhysPath, BasePath As String
   Dim BoolCross As Boolean = True
   
   VirPath = "/QuickStart"
   BasePath = ""
   
   Response.Write(Request.MapPath(VirPath, BasePath, BoolCross))

%>

</body> </html>

      </source>
   
  


Use map path (VB.net)

   <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>