File Path Parsing (VB) : Path « File Directory « ASP.NET Tutorial






<%@ Page Language="VB" %>
<%@ Import Namespace="System" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
    Public Sub Page_Load(Source As Object, E As EventArgs)
        PathPropertiesLiteral.Text = ""
    End Sub
    
    Public Sub ParsePath(Source As Object, E As EventArgs)
    
  Dim PropertyContainer As New StringBuilder()
    
        With PropertyContainer
            .Append("<Table border='0' width='100%'>")
            .Append("<Tr><Td>Full Path</Td>")
            .Append("<Td>" & Path.GetFullPath(FileNameTextBox.Text) & "</Td></Tr>")
            .Append("<Tr><Td>Root Drive</Td>")
            .Append("<Td>" & Path.GetPathRoot(FileNameTextBox.Text) & "</Td></Tr>")
            .Append("<Tr><Td>Directory Path</Td>")
            .Append("<Td>" & Path.GetDirectoryName(FileNameTextBox.Text) & "</Td></Tr>")
            .Append("<Tr><Td>File Name</Td>")
            .Append("<Td>" & Path.GetFileName(FileNameTextBox.Text) & "</Td></Tr>")
            .Append("<Tr><Td>File Name (Without Extension)</Td>")
            .Append("<Td>" & Path.GetFileNameWithoutExtension(FileNameTextBox.Text) & "</Td></Tr>")
            .Append("<Tr><Td>File Extension</Td>")
            .Append("<Td>" & Path.GetExtension(FileNameTextBox.Text) & "</Td></Tr>")
            .Append("<Tr><Td>Temporary Filename</Td>")
            .Append("<Td>" & Path.GetTempFileName() & "</Td></Tr>")
            .Append("<Tr><Td>Temprary Filepath</Td>")
            .Append("<Td>" & Path.GetTempPath() & "</Td></Tr>")
            .Append("<Tr><Td>Directory Separator</Td>")
            .Append("<Td>" & Path.DirectorySeparatorChar & "</Td></Tr>")
            .Append("<Tr><Td>Alt Directory Separator</Td>")
            .Append("<Td>" & Path.AltDirectorySeparatorChar & "</Td></Tr>")
            .Append("<Tr><Td>Path Separator</Td>")
            .Append("<Td>" & Path.PathSeparator & "</Td></Tr>")
            .Append("<Tr><Td>Volume Separator</Td>")
            .Append("<Td>" & Path.VolumeSeparatorChar & "</Td></Tr>")
            .Append("<Tr><Td>Invalid Path Characters</Td>")
            .Append("<Td>" & Path.InvalidPathChars & "</Td></Tr>")
      .Append("</Table>")
            
        End With

  PathPropertiesLiteral.Text = PropertyContainer.ToString
    
    End Sub

</script>
<html>
  <head>
    <title>CookBook :: File Path Parsing</title>
  </head>
  <body>
    <form runat="server">
      <h4>File Path Parser
      </h4>
      <h4>
        <asp:TextBox id="FileNameTextBox" runat="server"></asp:TextBox>
        &nbsp;<asp:Button id="ParsePathButton" onclick="ParsePath" runat="server" Text="Parse"></asp:Button>
      </h4>
      <hr />
    </form>
    <asp:Literal id="PathPropertiesLiteral" runat="server"></asp:Literal>
  </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)