ASP.Net/Server/Map Path

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

MapPath(file) (VB.net)

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



Showing ServerVariable values via the ServerVariables Collection in ASP.NET

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



Use map path (VB.net)

<%@ 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 = "<pre>" & _
               Server.HtmlEncode(TheFile.ReadToEnd()) & "</pre>"
         End Sub
         Sub Page_Unload()
            TheFile.Close()
         End Sub
      </script>
   </head>
<body>
   <asp:label id="Message" runat="server"/>
</body>
</html>