|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Want a new Job?
Chapters
Services
Feature Zones
|
IntroductionOne of the rich experiences in working with .NET is a huge collection of Base Class Libraries. The .NET Framework class library is a library of classes, interfaces, and value types that are included in the Microsoft .NET Framework SDK. This library provides access to system functionality and is designed to be the foundation on which .NET Framework applications, components, and controls are built. Details
To parse information of lots of files and directories, the The List of members of
Using the codeThis Sample code shows how to use protected void ProcessFile(string PathName)
{
try
{
FileInfo TheFile = new FileInfo(PathName);
if (TheFile.Exists)
{
DirectoryInfo Parent = TheFile.Directory;
ListContentsOfFolder(Parent);
DisplayFileInfo(TheFile);
return;
}
throw new FileNotFoundException();
}
catch(FileNotFoundException )
{
tbFolder.Text = PathName;
listFileItems.Items.Add(
"This file or folder does not exist");
}
catch(Exception e)
{
tbFolder.Text = PathName;
listFileItems.Items.Add("Error Processing");
listFileItems.Items.Add(e.Message);
}
finally
{
ListItems = false;
}
}The above sample code shows how to get the information of the file and display the contents of the file.protected void ProcessFolder(string PathName)
{
try
{
DirectoryInfo TheFolder = new DirectoryInfo(PathName);
if (TheFolder.Exists)
{
ListContentsOfFolder(TheFolder);
return;
}
throw new FileNotFoundException();
}
catch(FileNotFoundException )
{
tbFolder.Text = PathName;
listFolderItems.Items.Add(
"This folder or folder does not exist");
}
catch(Exception e)
{
tbFolder.Text = PathName;
listFolderItems.Items.Add("Problem occurred:");
listFolderItems.Items.Add(e.Message);
}
finally
{
ListItems = false;
}
}
The above code shows the folder names in the specified directory. To show the information of the file we have a small helper function called protected void DisplayFileInfo(FileInfo TheFile)
{
tbFileName.Text = TheFile.Name;
tbCreationTime.Text = TheFile.CreationTime.ToLongTimeString();
tbLastAccessTime.Text = TheFile.LastAccessTime.ToLongDateString();
tbLastWriteTime.Text = TheFile.LastWriteTime.ToLongDateString();
tbSize.Text = TheFile.Length.ToString() + " Bytes";
}
In order to delete, move, copy there are much simpler operation available in .NET SDK - like
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||