C#.Net Basic File Operation

Here there are basic syntax for File Operation.

Console.WriteLine(“*** File Operation ***”);

string sDirectoryPath = @”D:\TempFolder”;
string sFileName = “Test.txt”;
string sFilePath = sDirectoryPath + “\\” + sFileName;

//Directory Creation Time
Console.WriteLine(“Directory Creatiion Time :” + Directory.GetCreationTime(sDirectoryPath));

//File Creation Time
Console.WriteLine(“File Creatiion Time :” + File.GetCreationTime(sFilePath));

//Directory Path of File
Console.WriteLine(“Directory Name :” + Directory.GetParent(sFilePath));

//File Full Path
Console.WriteLine(“File Full Path :” + Path.GetFullPath(sFilePath));

//File Name
Console.WriteLine(“File Name :” + Path.GetFileName(sFilePath));

//File Extension
Console.WriteLine(“File Extension:” + Path.GetExtension(sFilePath));

//File Size
FileInfo fInfo = new FileInfo(sFilePath);
Console.WriteLine(“File Extension:” + fInfo.Length + ” bytes”);
//File Attrivutes
Console.WriteLine(“File Extension:” + fInfo.Attributes + ” bytes”);



Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s