Mega Code Archive

 
Categories / ASP.Net / File Directory
 

Inquiring Information About a File (C#)

<%@ Page Language="C#" %> <%@ Import Namespace="System.IO" %> <%@ Import Namespace="System" %> <script runat="server">     void Page_Load(object Source, EventArgs e)     {         ListFileInfoLiteral.Text = "";     FileTextBox.Text = Server.MapPath("Default.aspx");     }          public void DisplayFileInfo(object Source, EventArgs e)     {         FileInfo iFile;         iFile = new FileInfo(FileTextBox.Text);         if (iFile.Exists){      System.Text.StringBuilder sb = 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";     } </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>