How to Retrieving Details of a file in ASP.net.?


In this article I'm trying to explain how to retrieve details of a file using C#.net code. Here, we just enter path of that file based on that path if file is exists then it will display the details of that file. This article will help you for fresher as well as for beginners.

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.

Step-1:



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".

Step-2:



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.

Step-3:



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">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>

<asp:Label ID="lblPath" runat="server" Text="Enter name and path of a file : "></asp:Label>

<asp:TextBox ID="txtPath" runat="server"></asp:TextBox>
<br />
<br />
<asp:Button ID="btnView" runat="server" onclick="btnView_Click" Text="View" />
<br />
<br />
<br />
<asp:TextBox ID="txtDetails" runat="server" Height="72px" TextMode="MultiLine"
Width="310px"></asp:TextBox>

</div>
</form>
</body>
</html>

Step-4:



The design view of the page is looks becomes like below.

1

Step-5:



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)
{
string str;
try
{
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;
}
}


Step-6:



Now, execute the code by pressing F5 on keyboard then see the result how its looks become.

2

Conclusion:



I hope this article will help you those who are looking for the same and those who are beginners to perform the same task.


Article by naveensanagasetti
I hope you enjoyed to read my article, If you have any queries out of this then please post your comments.

Follow naveensanagasetti or read 139 articles authored by naveensanagasetti

Comments

No responses found. Be the first to comment...


  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:
    Email: