Click here to Skip to main content
15,910,211 members
Articles / Web Development / ASP.NET
Article

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

Rate me:
Please Sign up or sign in to vote.
1.48/5 (9 votes)
26 Feb 2007CPOL2 min read 21K   179   8   2
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)


Written By
Team Leader
Singapore Singapore
- B.Sc. degree in Computer Science.
- 4+ years experience in Visual C#.net and VB.net
- Obsessed in OOP style design and programming.
- Designing and developing Network security tools.
- Designing and developing a client/server application for sharing files among users in a way other than FTP protocol.
- Designing and implementing GSM gateway applications and bulk messaging.
- Windows Mobile and Symbian Programming
- Having knowledge with ERP solutions

The summary of my skills:
C#, VB.Net#,ASP.net, VC++, Java, WPF,WCF, Oracle, SQL Server, MS Access, Windows NT administration

Cheers
RRave
MCPD,MCTS
http://codegain.com

Comments and Discussions

 
QuestionEr....source code? Pin
sharpiesharpie26-Feb-07 2:12
sharpiesharpie26-Feb-07 2:12 
AnswerRe: Er....source code? Pin
Ravenet26-Feb-07 4:15
Ravenet26-Feb-07 4:15 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.