Retrieving Details of a file:
In this article I'm trying to explain how to retrieve details of a file using C#.net code. This article will help you for fresher as well as for beginners.
Follow below steps to achieve your goal.
Create a project and then right click on solution explorer then choose Add->New Item and then choose Web Form and give a name for that as "Retrievedetails.aspx".
Once Web Form has been created successfully then design the page by dragging and dropping 1 label control and 1 button control and 2 textbox controls into that design view.
Once design part has been completed successfully then the source code looks becomes like below.
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Retrievedetails.aspx.cs" Inherits="ASPnet_Retrievedetails" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<form id="form1" runat="server">
<asp:Label ID="lblPath" runat="server" Text="Enter name and path of a file : "></asp:Label>
<asp:TextBox ID="txtPath" runat="server"></asp:TextBox>
<asp:Button ID="btnView" runat="server" onclick="btnView_Click" Text="View" />
<asp:TextBox ID="txtDetails" runat="server" Height="72px" TextMode="MultiLine"
The design view of the page is looks becomes like below.
Once design part has been completed then double click on the button control then wrote below lines of code under button click event.
protected void btnView_Click(object sender, EventArgs e)
str = txtPath.Text;
txtDetails.Text="File Attributes : "+System.IO.File.GetAttributes(str)+" Created at :"
+System.IO.File.GetCreationTime(str).ToString()+" Last Accessed at :"+System.IO.File.GetLastAccessTime(str);
catch (Exception ex)
txtDetails.Text = ex.Message;
Now, execute the code by pressing F5 on keyboard then see the result how its looks become.
I hope this article will help you those who are looking for the same and those who are beginners to perform the same task.
No responses found. Be the first to comment...