Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / web / ASP.NET

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

1.48/5 (9 votes)
26 Feb 2007CPOL2 min read 2   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)]<br />/// <summary><br />/// Get File segment and size.<br />/// </summary><br />/// <param name="ParentPath"></param><br />/// <returns></returns><br />public string GetSegment (string ParentPath)<br />{<br /><br />string Container = string.Empty;<br />int segmentCount = 0;<br />long lastsegmentSize = 0;<br /><br />long fileSizeinBytes = 0;<br />try<br />{<br />if (!string.IsNullOrEmpty (ParentPath))<br />{<br />if (File.Exists (ParentPath))<br />{<br />FileInfo objRecordedFileInfo = new FileInfo (ParentPath);<br />fileSizeinBytes = objRecordedFileInfo.Length;<br /><br />if (fileSizeinBytes > Convert.ToInt64 (bufferSize))<br />{<br />segmentCount = Convert.ToInt32 (fileSizeinBytes / bufferSize);<br />lastsegmentSize = Convert.ToInt64 (fileSizeinBytes % bufferSize);<br />Container = segmentCount + "|" + lastsegmentSize + "|" + fileSizeinBytes;<br />}<br />else<br />{<br />Container = segmentCount + "|" + fileSizeinBytes + fileSizeinBytes;<br />}<br />}<br />else<br />{<br />Container = segmentCount + "|" + lastsegmentSize + fileSizeinBytes;<br />}<br />}<br />}<br />#region [ Exception Handling in Presetation Layer ]<br /><br />#region [General Exception ]<br />catch (Exception ex)<br />{<br />throw ex;<br />}<br />#endregion<br /><br />#endregion<br /><br />return Container;<br />}<br />#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)<br />{<br />FileInfo objFileInfo=new FileInfo(Filename);<br />FileAttributes objFileAttributes = objFileInfo.Attributes;<br />switch (objFileAttributes)<br />{<br />case FileAttributes.Archive:<br />chkArchive.Checked = true;<br />break;<br />case FileAttributes.Compressed:<br />chkCompressed.Checked = true;<br />break;<br />case FileAttributes.Device:<br />chkDevice.Checked = true;<br />break;<br />case FileAttributes.Directory:<br />chkDirectory.Checked = true;<br />break;<br />case FileAttributes.Encrypted:<br />chkEncrypted.Checked = true;<br />break;<br />case FileAttributes.Hidden:<br />chkHidden.Checked = true;<br />break;<br />case FileAttributes.Normal:<br />chkNormal.Checked = true;<br />break;<br />case FileAttributes.NotContentIndexed:<br />chkNotContentIndexed.Checked = true;<br />break;<br />case FileAttributes.Offline:<br />chkOffline.Checked = true;<br />break;<br />case FileAttributes.ReadOnly:<br />chkReadOnly.Checked = true;<br />break; <br />case FileAttributes.System:<br />chkSystem.Checked = true;<br />break;<br />case FileAttributes.Temporary:<br />chkTemporary.Checked = true;<br />break;<br /><br />}<br />}

</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!!!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)