Inquiring Information About a File (VB) : FileInfo « File Directory « ASP.Net






Inquiring Information About a File (VB)


<%@ Page Language="VB" %>
<%@ Import Namespace="System.IO" %>
<%@ Import Namespace="System" %>
<script runat="server">
    Public Sub Page_Load(Source As Object, Sender As EventArgs)
    
        ListFileInfoLiteral.Text = ""
    FileTextBox.Text = Server.MapPath("Default.aspx")
    End Sub
    
  Public Sub DisplayFileInfo(Source As Object, Sender As EventArgs)
    Dim iFile As FileInfo
    iFile = New FileInfo(FileTextBox.Text)
    If iFile.Exists Then
      Dim sb As New System.Text.StringBuilder(1000)
      
      sb.Append("<table border='0' width='50%'>")
      sb.Append("<tr>")
      sb.Append("<td>Name</td>")
      sb.Append("<td>" & iFile.Name & "</td>")
      sb.Append("</tr><tr>")
      sb.Append("<td>Path\Name</td>")
      sb.Append("<td>" & iFile.FullName & "</td>")
      sb.Append("</tr><tr>")
      sb.Append("<td>Extension</td>")
      sb.Append("<td>" & iFile.Extension & "</td>")
      sb.Append("</tr><tr>")
      sb.Append("<td>Size</td>")
      sb.Append("<td>" & iFile.Length & " bytes</td>")
      sb.Append("</tr><tr>")
      sb.Append("<td>Attributes</td>")
      sb.Append("<td>" & iFile.Attributes.ToString() & "</td>")
      sb.Append("</tr><tr>")
      sb.Append("<td>Creation Time</td>")
      sb.Append("<td>" & iFile.CreationTime & "</td>")
      sb.Append("</tr><tr>")
      sb.Append("<td>Last Accessed</td>")
      sb.Append("<td>" & iFile.LastAccessTime & "</td>")
      sb.Append("</tr><tr>")
      sb.Append("<td>Last Modified</td>")
      sb.Append("<td>" & iFile.LastWriteTime & "</td>")
      sb.Append("</tr></table>")
      ListFileInfoLiteral.Text = sb.ToString()    
    Else
      ListFileInfoLiteral.Text = "The file does not exist"
    End If
  End Sub
</script>
<HTML>
  <HEAD>
    <title>Inquiring Information About a File</title>
  </HEAD>
  <body>
    <form runat="server">
      <h4>Type&nbsp;path\name of&nbsp;file and click the button.
      </h4>
      <p>
        <asp:TextBox id="FileTextBox" runat="server" ReadOnly="True"></asp:TextBox>
        &nbsp;<asp:Button id="GetFileInfoButton" onclick="DisplayFileInfo" runat="server" Text="File Information"></asp:Button>
      </p>
      <hr align="left" width="50%">
      <p>
        <asp:Literal id="ListFileInfoLiteral" runat="server"></asp:Literal>
      </p>
    </form>
  </body>
</HTML>

 








Related examples in the same category

1.Inquiring Information About a File (C#)
2.Copying or Moving a File (C#)
3.Copying or Moving a File (VB)