Using the Path class (VB) : Path « File Directory « ASP.NET Tutorial





<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
        If Page.IsPostBack Then
            Me.lblRootPath.Text = Path.GetPathRoot(Me.txtPathName.Text)
            Me.lblDirectoryName.Text = Path.GetDirectoryName(Me.txtPathName.Text)
            Me.lblFileName.Text = Path.GetFileName(Me.txtPathName.Text)
            Me.lblFileNameWithoutExtension.Text = Path.GetFileNameWithoutExtension(Me.txtPathName.Text)
            Me.lblExtension.Text = Path.GetExtension(Me.txtPathName.Text)

            Me.lblTemporaryPath.Text = Path.GetTempPath()
            Me.lblDirectorySeparatorChar.Text = Path.DirectorySeparatorChar.ToString()
            Me.lblAltDirectorySeparatorChar.Text = Path.AltDirectorySeparatorChar.ToString()
            Me.lblVolumeSeparatorChar.Text = Path.VolumeSeparatorChar.ToString()
            Me.lblPathSeparator.Text = Path.PathSeparator.ToString()

            Me.lblInvalidChars.Text = HttpUtility.HtmlEncode(New String(Path.GetInvalidPathChars()))
            Me.lblInvalidFileNameChars.Text = HttpUtility.HtmlEncode(New String(Path.GetInvalidFileNameChars()))
        End If
    End Sub

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Untitled Page</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        Working with the Path Class<br />
        <br />
        Enter a path name:
        <asp:TextBox ID="txtPathName" runat="server"></asp:TextBox><br />
        <asp:Button ID="Button1" runat="server" Text="Button" /><br />
        <br />
        Root Path = 
        <asp:Label ID="lblRootPath" runat="server" Text="Label" />
        <br />
        Directory =
        <asp:Label ID="lblDirectoryName" runat="server" Text="Label" />
        <br />
        Filename =
        <asp:Label ID="lblFileName" runat="server" Text="Label" />
        <br />
        Filename (without extension) =
        <asp:Label ID="lblFileNameWithoutExtension" runat="server" Text="Label" />
        <br />
        Extension =
        <asp:Label ID="lblExtension" runat="server" Text="Label" />
        <br />
        <br />
        Temporary Directory =
        <asp:Label ID="lblTemporaryPath" runat="server" Text="Label" />
        <br />
        Directory Separator Character =
        <asp:Label ID="lblDirectorySeparatorChar" runat="server" Text="Label" />
        <br />
        Alt Directory Separator Character =
        <asp:Label ID="lblAltDirectorySeparatorChar" runat="server" Text="Label" />
        <br />
        Volume Separator Character =
        <asp:Label ID="lblVolumeSeparatorChar" runat="server" Text="Label" />
        <br />
        Path Separator Character =
        <asp:Label ID="lblPathSeparator" runat="server" Text="Label" />
        <br />
        Invalid Path Characters =
        <asp:Label ID="lblInvalidChars" runat="server" Text="Label" />
        <br />
        Invalid FileName Characters =
        <asp:Label ID="lblInvalidFileNameChars" runat="server" Text="Label" />
    
    </div>
    </form>
</body>
</html>










10.5.Path
10.5.1.Using the Path class (C#)
10.5.2.Using the Path class (VB)
10.5.3.File Path Parsing (C#)
10.5.4.File Path Parsing (VB)