How to Get file information using C#?

How to Get file information using C#?
Just import system.Io name space in your code behind.
[code]
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.IO;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string fPath = Server.MapPath("YourFileName");
FileInfo fInfo = new FileInfo(fPath);
string strFileInfo;
if (fInfo.Exists)
{
strFileInfo = "Name: " + fInfo.Name + "
";
strFileInfo += "Location: " + fInfo.FullName + "
";
strFileInfo += "Created on: " + fInfo.CreationTime + "
";
strFileInfo += "Extension: " + fInfo.Extension;

}
else
{
strFileInfo = "The file " + fPath + " was not found.";
}
Response.Write(strFileInfo);

}
}

[/code]

No comments:

Post a Comment

Plz Share your comments...