65.9K
CodeProject is changing. Read more.
Home

This is basically focus files attributes with .net 2.0 IO base class library

starIcon
emptyStarIcon
starIcon
emptyStarIconemptyStarIconemptyStarIcon

1.48/5 (9 votes)

Feb 26, 2007

CPOL

2 min read

viewsIcon

21050

downloadIcon

179

THis atricle so some useful infomation any type of files and basic file attributes also

Screenshot - FM1.jpg

Download FileManagement_demo.zip - 11.1 KB

Download FileManagement_src.zip - 156 KB

Introduction

This Article explain some useful funcatinality in System.IO.FileInfo class. and also few useful method for the file size customization.

Background

The Windows system could store additional information like provide additional inforamtion with fileInfo class and more and more. and base dll System.dll.

It's simple user interface for this demo,and also source code can be download bellow link

Using Code

code snippts

<code>

#region [ string GetSegment (string ParentPath)]
/// <summary>
/// Get File segment and size.
/// </summary>
/// <param name="ParentPath"></param>
/// <returns></returns>
public string GetSegment (string ParentPath)
{

string Container = string.Empty;
int segmentCount = 0;
long lastsegmentSize = 0;

long fileSizeinBytes = 0;
try
{
if (!string.IsNullOrEmpty (ParentPath))
{
if (File.Exists (ParentPath))
{
FileInfo objRecordedFileInfo = new FileInfo (ParentPath);
fileSizeinBytes = objRecordedFileInfo.Length;

if (fileSizeinBytes > Convert.ToInt64 (bufferSize))
{
segmentCount = Convert.ToInt32 (fileSizeinBytes / bufferSize);
lastsegmentSize = Convert.ToInt64 (fileSizeinBytes % bufferSize);
Container = segmentCount + "|" + lastsegmentSize + "|" + fileSizeinBytes;
}
else
{
Container = segmentCount + "|" + fileSizeinBytes + fileSizeinBytes;
}
}
else
{
Container = segmentCount + "|" + lastsegmentSize + fileSizeinBytes;
}
}
}
#region [ Exception Handling in Presetation Layer ]

#region [General Exception ]
catch (Exception ex)
{
throw ex;
}
#endregion

#endregion

return Container;
}
#endregion

</code>

and also you can customize buffer size.

and another simple snippt for File basic attribue provide by the Microsoft class library,but here demo

Screenshot - FM2.jpg

and snippts

<code>

private void GetFileAttibutes (string Filename)
{
FileInfo objFileInfo=new FileInfo(Filename);
FileAttributes objFileAttributes = objFileInfo.Attributes;
switch (objFileAttributes)
{
case FileAttributes.Archive:
chkArchive.Checked = true;
break;
case FileAttributes.Compressed:
chkCompressed.Checked = true;
break;
case FileAttributes.Device:
chkDevice.Checked = true;
break;
case FileAttributes.Directory:
chkDirectory.Checked = true;
break;
case FileAttributes.Encrypted:
chkEncrypted.Checked = true;
break;
case FileAttributes.Hidden:
chkHidden.Checked = true;
break;
case FileAttributes.Normal:
chkNormal.Checked = true;
break;
case FileAttributes.NotContentIndexed:
chkNotContentIndexed.Checked = true;
break;
case FileAttributes.Offline:
chkOffline.Checked = true;
break;
case FileAttributes.ReadOnly:
chkReadOnly.Checked = true;
break;
case FileAttributes.System:
chkSystem.Checked = true;
break;
case FileAttributes.Temporary:
chkTemporary.Checked = true;
break;

}
}

</code>

Thanks Guys

And please it's my First article , so may be have mistake any category in the viewer, so please tell any suggestions to me via email

Thanks Enjoy!!!