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