<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>devarea</title>
	<atom:link href="http://devarea.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://devarea.wordpress.com</link>
	<description>weblog for developer</description>
	<lastBuildDate>Fri, 03 Apr 2009 03:54:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='devarea.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>devarea</title>
		<link>http://devarea.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://devarea.wordpress.com/osd.xml" title="devarea" />
	<atom:link rel='hub' href='http://devarea.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Disable Autorun</title>
		<link>http://devarea.wordpress.com/2009/04/03/disable-autorun/</link>
		<comments>http://devarea.wordpress.com/2009/04/03/disable-autorun/#comments</comments>
		<pubDate>Fri, 03 Apr 2009 03:51:22 +0000</pubDate>
		<dc:creator>bugmonster</dc:creator>
				<category><![CDATA[Utility Tips]]></category>
		<category><![CDATA[autorun]]></category>

		<guid isPermaLink="false">http://devarea.wordpress.com/?p=16</guid>
		<description><![CDATA[ป้องกัน Virus จาก Trump drive โดยการ Disable-autorun ในปัจจุบันทุกคนที่ใช้ COMPUTER มักจะมี Trump Drive สำหรับเก็บข้อมูลส่วนตัว ซึ่งในบาง trump drive นั้นจะมีโปรแกรม auto-run เพื่อว่าเมื่อเสียบ trump drive ไปแล้ว โปรแกรมจะได้ทำงานได้ทันที ซึ่งจริงๆแล้วตรงนี้เป็นประโยชน์ ทำให้การใช้งานได้สะดวก แต่ในขณะเดียวกัน ก็มีคนจำนวนหนึ่ง กลับใช้ auto-run นี้ ในการแพร่กระจาย virus ทั้งที่น่ารังเกลียด คือการให้โปรแกรม auto-run ทำการขโมย หรือ ลบ ข้อมูลในเครื่อง computer ที่เสียบ trump drive นั้นเข้า ซึ่งจะได้ภาพ วิธีที่จัดการปัญหานี้ แนะนำให้ disable auto-run ไปเลย ซึ่งน่าจะเป็นการดีกว่าที่ปล่อยให้ trump drive หรือ CD [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=16&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><strong>ป้องกัน Virus จาก Trump drive โดยการ Disable-autorun</strong></p>
<p><!-- Main --><span>ในปัจจุบันทุกคนที่ใช้ COMPUTER มักจะมี Trump Drive สำหรับเก็บข้อมูลส่วนตัว ซึ่งในบาง trump drive นั้นจะมีโปรแกรม auto-run เพื่อว่าเมื่อเสียบ trump drive ไปแล้ว โปรแกรมจะได้ทำงานได้ทันที ซึ่งจริงๆแล้วตรงนี้เป็นประโยชน์ ทำให้การใช้งานได้สะดวก แต่ในขณะเดียวกัน ก็มีคนจำนวนหนึ่ง กลับใช้ auto-run นี้ ในการแพร่กระจาย virus ทั้งที่น่ารังเกลียด คือการให้โปรแกรม auto-run ทำการขโมย หรือ ลบ ข้อมูลในเครื่อง computer ที่เสียบ trump drive นั้นเข้า</span><span><br />
<img src="http://www.bloggang.com/data/spnet/picture/1223892646.gif" alt="" /><br />
</span><span><br />
ซึ่งจะได้ภาพ</span></p>
<p>วิธีที่จัดการปัญหานี้ แนะนำให้ disable auto-run ไปเลย ซึ่งน่าจะเป็นการดีกว่าที่ปล่อยให้ trump drive หรือ CD ที่มี auto-run ทำงานมาขโมยข้อมูลต่างๆของเรา<br />
วิธีการ disable-autorun ใน window XP นั้นทำได้ง่ายมาก</p>
<p>1. เรียกโปรแกม gpedit.msc</p>
<p><img src="http://www.bloggang.com/data/spnet/picture/1223892735.gif" border="0" alt="" width="450" height="321" /></p>
<p>2. Click ที่ Aminstator Templates/System/Trun off Autoplay</p>
<p><img src="http://www.bloggang.com/data/spnet/picture/1223892842.gif" border="0" alt="" width="450" height="326" /></p>
<p>3. แก้ไขเป็น Eabled และ All drives</p>
<p><img src="http://www.bloggang.com/data/spnet/picture/1223892924.gif" alt="" /></p>
<p><span>4. Click OK / Reboot</span></p>
<p>ให้ทดสอบง่ายๆ ด้วยการเสียบแผ่น CD ที่มีโปรแกรม autorun ต่างๆดู จะเห็นว่าโปรแกรมจะไม่ได้ขึ้นมาอัตโนมัติ เพียงเท่านี้ เครื่อง computer ของคุณก็ลดความเสี่ยงต่อการถูก Hack / Virus ได้</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/devarea.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/devarea.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/devarea.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/devarea.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/devarea.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/devarea.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/devarea.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/devarea.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/devarea.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/devarea.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/devarea.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/devarea.wordpress.com/16/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/devarea.wordpress.com/16/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/devarea.wordpress.com/16/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=16&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devarea.wordpress.com/2009/04/03/disable-autorun/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9abeafc7358438edab347736f91998c9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bugmonster</media:title>
		</media:content>

		<media:content url="http://www.bloggang.com/data/spnet/picture/1223892646.gif" medium="image" />

		<media:content url="http://www.bloggang.com/data/spnet/picture/1223892735.gif" medium="image" />

		<media:content url="http://www.bloggang.com/data/spnet/picture/1223892842.gif" medium="image" />

		<media:content url="http://www.bloggang.com/data/spnet/picture/1223892924.gif" medium="image" />
	</item>
		<item>
		<title>FreeBSD Technologies in New Firefox 3 Browser</title>
		<link>http://devarea.wordpress.com/2008/06/26/freebsd-technologies-in-new-firefox-3-browser/</link>
		<comments>http://devarea.wordpress.com/2008/06/26/freebsd-technologies-in-new-firefox-3-browser/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 03:43:27 +0000</pubDate>
		<dc:creator>bugmonster</dc:creator>
				<category><![CDATA[Unix/Linux]]></category>
		<category><![CDATA[Firefox]]></category>
		<category><![CDATA[FreeBSD]]></category>

		<guid isPermaLink="false">http://devarea.wordpress.com/?p=14</guid>
		<description><![CDATA[Boulder, CO (PRWEB) June 23, 2008 &#8212; Mozilla this week released the highly anticipated Firefox 3 browser. The FreeBSD Project congratulates the Mozilla project on a multi-year effort that culminated in a product that is both faster and more secure than its predecessors, with innovative new features. Several important features of the Firefox browser were [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=14&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Boulder, CO (PRWEB) June 23, 2008 &#8212; Mozilla this week released the highly anticipated Firefox 3 browser. The FreeBSD Project congratulates the Mozilla project on a multi-year effort that culminated in a product that is both faster and more secure than its predecessors, with innovative new features. Several important features of the Firefox browser were incorporated from technologies adopted from the FreeBSD project. Technology from the FreeBSD project has a long history of being used inside other open source projects such as Firefox.</p>
<p><span id="more-14"></span></p>
<p>One of the FreeBSD technologies used by Firefox 3 is the new memory allocator, &#8220;jemalloc&#8221;, which was written by FreeBSD developer Jason Evans for the FreeBSD 7 operating system. jemalloc is a fast, efficient memory allocator with excellent performance on multiprocessor machines. Though already a part of the FreeBSD 7 operating system, the Mozilla project has chosen to also incorporate it directly inside the Firefox 3 browser to improve memory performance and reduce memory use on other operating systems with legacy memory allocators.</p>
<p>According to the blog of Firefox developer Stuart Parmenter, &#8220;Our automated tests on Windows Vista showed a 22% drop in memory usage when we turned jemalloc on.&#8221; Commenting on the Linux version of the browser, he wrote, &#8220;We saw a good performance increase and a drop in memory.&#8221;</p>
<p>Another FreeBSD technology used by Firefox is the &#8220;bsdiff&#8221; binary patch system written by Colin Percival as part of the FreeBSD Update mechanism for updating the FreeBSD operating system. By using bsdiff, Firefox is able to dramatically reduce the size of its software updates, meaning faster downloads for end users. In addition to being used by FreeBSD and Firefox, bsdiff is used by Apple to distribute updates to the OS X operating system.</p>
<p>The FreeBSD operating system is supporting Firefox in other ways, too. FreeBSD was integral in delivering Firefox software into the hands of users through its association with the Internet Systems Consortium (ISC), which operates one of the Mozilla project&#8217;s primary download mirrors, mozilla.isc.org.</p>
<p>ISC is a long-time supporter of the FreeBSD project, and FreeBSD 7 powers the mirror that withstood a sustained download rate of a gigabit per second, during peak download periods throughout Firefox&#8217;s world record breaking &#8220;Download Day.&#8221;</p>
<p>&#8220;ISC saw four times the normal volume of downloads from the mozilla.isc.org site during Download Day,&#8221; said Peter Losher, Hosted@ISC Programme manager. &#8220;As usual, FreeBSD proved to be a rock-solid platform enabling us to deliver content without incident.&#8221;</p>
<h4>About the FreeBSD Project:</h4>
<p>Building on a 30 year development history, the FreeBSD operating system is descended from the pioneering code upon which much of the Internet and modern computing was founded. It continues to be actively developed, with world-class stability, performance and modern features not available in other operating systems, even some of the best commercial ones.</p>
<p>FreeBSD technology can be found throughout the IT industry, providing key components of Apple&#8217;s OS X, network infrastructure from Juniper, Nokia, IronPort and other vendors, storage appliances from NetApp and Isilon, and even appearing from time to time in Microsoft Windows, among many other products.</p>
<p>The FreeBSD operating system is freely available under the BSD license, a business-friendly open source license that encourages code reuse and adoption within both open-source and proprietary products. Our mission is to provide world-class operating system code and technologies to all users for use in their own systems, regardless of their eventual disposition.</p>
<p>By choosing to build their products on top of FreeBSD source code, companies remain in control of deciding when and how their changes should be contributed back to the community. However, our developers are ready to work with companies and projects who make use of FreeBSD source code, and many companies have found that engaging with the open source community helps to reduce their integration and maintenance costs.</p>
<p>For more information about the FreeBSD operating system, please visit <a href="http://www.freebsd.org/" target="_blank">http://www.freebsd.org/</a>, where the operating system is also available free for download or for purchase on CD or DVD through our partner organizations.</p>
<h4>About The FreeBSD Foundation:</h4>
<p>The FreeBSD Foundation is a 501(c)(3) non-profit organization dedicated to supporting the FreeBSD Project and community. The Foundation gratefully accepts donations from individuals and businesses, using them to fund and manage projects, sponsor FreeBSD events, Developer Summits and provide travel grants to FreeBSD developers. In addition, the Foundation represents the FreeBSD Project in executing contracts, license agreements, and other legal arrangements that require a recognized legal entity. The FreeBSD Foundation is entirely supported by donations. More information about The FreeBSD Foundation is available on the web at <a href="http://www.freebsdfoundation.org/" target="_blank">http://www.FreeBSDFoundation.org/</a>.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/devarea.wordpress.com/14/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/devarea.wordpress.com/14/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/devarea.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/devarea.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/devarea.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/devarea.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/devarea.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/devarea.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/devarea.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/devarea.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/devarea.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/devarea.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/devarea.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/devarea.wordpress.com/14/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/devarea.wordpress.com/14/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/devarea.wordpress.com/14/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=14&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devarea.wordpress.com/2008/06/26/freebsd-technologies-in-new-firefox-3-browser/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9abeafc7358438edab347736f91998c9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bugmonster</media:title>
		</media:content>
	</item>
		<item>
		<title>Requesting Ubuntu FREE CDs</title>
		<link>http://devarea.wordpress.com/2008/06/25/requesting-ubuntu-free-cds-from-shipit/</link>
		<comments>http://devarea.wordpress.com/2008/06/25/requesting-ubuntu-free-cds-from-shipit/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 09:38:04 +0000</pubDate>
		<dc:creator>bugmonster</dc:creator>
				<category><![CDATA[Unix/Linux]]></category>

		<guid isPermaLink="false">http://devarea.wordpress.com/?p=11</guid>
		<description><![CDATA[Requesting CDs from ShipIt Kubuntu is available free of charge and we can send you CDs of the latest version (8.04 (Hardy Heron)) with no extra cost, but the delivery may take up to ten weeks, so you should consider downloading the CD images if you have a fast Internet connection. More&#8230;<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=11&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<div class="body">
<div>
<h1>Requesting CDs from ShipIt</h1>
<p></p>
<p>Kubuntu is available free of charge and we can send you CDs of the latest version (8.04 (Hardy Heron)) with no extra cost, but the delivery may take up to ten weeks, so you should consider downloading the CD images if you have a fast Internet connection.
    </p>
</p>
<div id="chooseLinks">
<div>
          <a href="http://www.kubuntu.org/download.php" target="_blank"><span>More&#8230;</span></a>
        </div>
</p></div>
</p></div>
</p></div>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/devarea.wordpress.com/11/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/devarea.wordpress.com/11/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/devarea.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/devarea.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/devarea.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/devarea.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/devarea.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/devarea.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/devarea.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/devarea.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/devarea.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/devarea.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/devarea.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/devarea.wordpress.com/11/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/devarea.wordpress.com/11/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/devarea.wordpress.com/11/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=11&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devarea.wordpress.com/2008/06/25/requesting-ubuntu-free-cds-from-shipit/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9abeafc7358438edab347736f91998c9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bugmonster</media:title>
		</media:content>
	</item>
		<item>
		<title>Compute and Verify Hash Value Using C#</title>
		<link>http://devarea.wordpress.com/2008/06/25/compute-and-verify-hash-value/</link>
		<comments>http://devarea.wordpress.com/2008/06/25/compute-and-verify-hash-value/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 08:19:04 +0000</pubDate>
		<dc:creator>bugmonster</dc:creator>
				<category><![CDATA[Hash]]></category>
		<category><![CDATA[Security]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[MD5]]></category>
		<category><![CDATA[SHA]]></category>

		<guid isPermaLink="false">http://devarea.wordpress.com/?p=9</guid>
		<description><![CDATA[ฟังก์ชันสำหรับคำนวนค่า Hash ของไฟล์ โดยสนับสนุนอัลกอริทึ่ม MD5, SHA-1, SHA-256, SHA-384, SHA-512 public static string ComputeMD5Hash(string fileName) { &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return ComputeHash(fileName, new MD5CryptoServiceProvider()); } public static string ComputeSHA1Hash(string fileName) { &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return ComputeHash(fileName, new SHA1Managed()); } public static string ComputeSHA256Hash(string fileName) { &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return ComputeHash(fileName, new SHA256Managed()); } public static string ComputeSHA384Hash(string fileName) { &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;return ComputeHash(fileName, new SHA384Managed()); } public static [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=9&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>ฟังก์ชันสำหรับคำนวนค่า Hash ของไฟล์ โดยสนับสนุนอัลกอริทึ่ม MD5, SHA-1, SHA-256, SHA-384, SHA-512<br />
<span id="more-9"></span><br />
public static string ComputeMD5Hash(string fileName)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ComputeHash(fileName, new MD5CryptoServiceProvider());<br />
}</p>
<p>public static string ComputeSHA1Hash(string fileName)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ComputeHash(fileName, new SHA1Managed());<br />
}</p>
<p>public static string ComputeSHA256Hash(string fileName)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ComputeHash(fileName, new SHA256Managed());<br />
}</p>
<p>public static string ComputeSHA384Hash(string fileName)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ComputeHash(fileName, new SHA384Managed());<br />
}</p>
<p>public static string ComputeSHA512Hash(string fileName)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return ComputeHash(fileName, new SHA512Managed());<br />
}</p>
<p>public static string ComputeHash(string fileName, HashAlgorithm hashAlgorithm)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;FileStream stmcheck = File.OpenRead(fileName);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;try<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;byte[] hash = hashAlgorithm.ComputeHash(stmcheck);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string computed = BitConverter.ToString(hash).Replace(&#8220;-&#8221;, &#8220;&#8221;);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return computed;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;finally<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;stmcheck.Close();<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br />
}</p>
<p>public static bool VerifyHash(string fileName,<br />
string hashAlgorithm,<br />
string hashValue)<br />
{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;string expectedHashString = &#8220;&#8221;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Make sure that hashing algorithm name is specified.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (hashAlgorithm == null)<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hashAlgorithm = &#8220;&#8221;;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Size of hash is based on the specified algorithm.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;switch (hashAlgorithm.ToUpper())<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &#8220;SHA1&#8243;:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Compute a new hash string to compare.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expectedHashString = ComputeSHA1Hash(fileName);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &#8220;SHA256&#8243;:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Compute a new hash string to compare.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expectedHashString = ComputeSHA256Hash(fileName);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &#8220;SHA384&#8243;:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Compute a new hash string to compare.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expectedHashString = ComputeSHA384Hash(fileName);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;case &#8220;SHA512&#8243;:<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Compute a new hash string to compare.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expectedHashString = ComputeSHA512Hash(fileName);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;default: // Must be MD5<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;expectedHashString = ComputeMD5Hash(fileName);<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;break;<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}</p>
<p>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// If the computed hash matches the specified hash,<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// the plain text value must be correct.<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;return (hashValue == expectedHashString);<br />
}</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/devarea.wordpress.com/9/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/devarea.wordpress.com/9/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/devarea.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/devarea.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/devarea.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/devarea.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/devarea.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/devarea.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/devarea.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/devarea.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/devarea.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/devarea.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/devarea.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/devarea.wordpress.com/9/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/devarea.wordpress.com/9/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/devarea.wordpress.com/9/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=9&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devarea.wordpress.com/2008/06/25/compute-and-verify-hash-value/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9abeafc7358438edab347736f91998c9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bugmonster</media:title>
		</media:content>
	</item>
		<item>
		<title>Working with Files in C#</title>
		<link>http://devarea.wordpress.com/2008/06/25/working-with-files-in-c/</link>
		<comments>http://devarea.wordpress.com/2008/06/25/working-with-files-in-c/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 08:00:49 +0000</pubDate>
		<dc:creator>bugmonster</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[file]]></category>

		<guid isPermaLink="false">http://devarea.wordpress.com/?p=7</guid>
		<description><![CDATA[This article was contributed by Anand Narayanaswamy.In this article, you will learn how to manipulate directories and files in your system. Further, we will discuss how to read from and write to a file by using the powerful .NET classes. The Namespace System.IO provides all the necessary classes, methods, and properties for manipulating directories and [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=7&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><span class="bodycopy"><br />
<span class="bodycopy">This article was contributed by <a href="http://www.learnxpress.com/" target="new">Anand Narayanaswamy</a>.In this article, you will learn how to manipulate directories and files in your system. Further, we will discuss how to read from and write to a file by using the powerful .NET classes.<br />
</span></span><span id="more-7"></span><strong>The Namespace</strong></p>
<p><a href="http://www.codeguru.com/csharp/csharp/cs_syntax/anandctutorials/article.php/c5861/#more"></a></p>
<p>System.IO provides all the necessary classes, methods, and properties for manipulating directories and files. Table 1 elaborates the main classes under this namespace.</p>
<table border="2" cellspacing="2" cellpadding="2">
<tbody>
<tr bgcolor="#ffff99">
<td valign="top"><strong>Class</strong></td>
<td valign="top"><strong>Purpose/Use</strong></td>
</tr>
<tr>
<td valign="top">Binary Reader and Writer</td>
<td valign="top">Read and write primitive data types</td>
</tr>
<tr>
<td valign="top">Directory, File, DirectoryInfo, and FileInfo</td>
<td valign="top">Create, delete, and move files and directories. Get specific information about the files by making use of the properties defined in these classes.</td>
</tr>
<tr>
<td valign="top">FileStream</td>
<td valign="top">Access the files in a random fashion</td>
</tr>
<tr>
<td valign="top">MemoryStream</td>
<td valign="top">Access data stored in memory</td>
</tr>
<tr>
<td valign="top">StreamWriter and StreamReader</td>
<td valign="top">Read and write textual information</td>
</tr>
<tr>
<td valign="top">StringReader and StringWriter</td>
<td valign="top">Read and write textual Information from a string buffer</td>
</tr>
</tbody>
</table>
<p><em><strong>Table 1—Classes under System.IO</strong></em></p>
<h3><strong>Working with DirectoryInfo and FileInfo classes</strong></h3>
<p>The base class of DirectoryInfo and FileInfo is FileSystemInfo. This is an abstract class, meaning you can&#8217;t instantiate this class. But you can use the properties defined by this class. Table 2 elaborates its properties and methods.</p>
<table border="2" cellspacing="2" cellpadding="2">
<tbody>
<tr bgcolor="#ffff99">
<td valign="top"><strong>Properties</strong></td>
<td valign="top"><strong>Purpose/Use</strong></td>
</tr>
<tr>
<td valign="top">Attributes</td>
<td valign="top">Returns attributes associated with a file. Takes FileAttributes enumeration values</td>
</tr>
<tr>
<td valign="top">CreationTime</td>
<td valign="top">Returns the time of creation of the file</td>
</tr>
<tr>
<td valign="top">Exists</td>
<td valign="top">Checks whether a supplied file is a directory or not</td>
</tr>
<tr>
<td valign="top">Extension</td>
<td valign="top">Returns the file extension</td>
</tr>
<tr>
<td valign="top">LastAccessTime</td>
<td valign="top">Returns last accessed time of the file</td>
</tr>
<tr>
<td valign="top">FullName</td>
<td valign="top">Returns the full path of the file</td>
</tr>
<tr>
<td valign="top">LastWriteTime</td>
<td valign="top">Returns the time of last written activity to the file</td>
</tr>
<tr>
<td valign="top">Name</td>
<td valign="top">Returns the name of a given file</td>
</tr>
<tr>
<td valign="top">Delete()</td>
<td valign="top">Deletes a file. Be careful when using this method.</td>
</tr>
</tbody>
</table>
<p><em><strong>Table 2—Members of FileSystemInfo class</strong></em></p>
<p>The DirectoryInfo class provides methods for creating, moving, and deleting directories. To make use of the above properties, create an object of the DirectoryInfo class as shown in Listing 1:</p>
<p><em><strong>Listing 1</strong></em></p>
<pre>DirectoryInfo dir1 = <span class="codeKeyword">new</span> DirectoryInfo(@"F:\WINNT");</pre>
<p>You then can access the properties by using the object <em><strong>dir1</strong></em>, as shown in the code fragment in Listing 2:</p>
<p><em><strong>Listing 2</strong></em></p>
<pre>Console.WriteLine("Full Name is : {0}", dir1.FullName);
Console.WriteLine("Attributes are : {0}",
                   dir1.Attributes.ToString());</pre>
<p>You can also apply the values of FileAttributes enumeration. Its values are shown in Table 3.</p>
<table border="2" cellspacing="2" cellpadding="2">
<tbody>
<tr bgcolor="#ffff99">
<td valign="top"><strong>Properties</strong></td>
<td valign="top"><strong>Purpose/Use</strong></td>
</tr>
<tr>
<td valign="top">Archive</td>
<td valign="top">Returns the file&#8217;s Archive status</td>
</tr>
<tr>
<td valign="top">Compressed</td>
<td valign="top">Returns whether the file is compressed or not</td>
</tr>
<tr>
<td valign="top">Directory</td>
<td valign="top">Returns whether the file is a directory or not</td>
</tr>
<tr>
<td valign="top">Encrypted</td>
<td valign="top">Returns whether the file is encrypted or not</td>
</tr>
<tr>
<td valign="top">Hidden</td>
<td valign="top">Returns whether the file is hidden or not</td>
</tr>
<tr>
<td valign="top">Offline</td>
<td valign="top">Signifies that the data is not available</td>
</tr>
<tr>
<td valign="top">ReadOnly</td>
<td valign="top">Indicates that the file is read only</td>
</tr>
<tr>
<td valign="top">System</td>
<td valign="top">Indicates that the file is a System file (probably a file under the Windows folder)</td>
</tr>
</tbody>
</table>
<p><em><strong>Table 3—FileAttributes Enumeration Values</strong></em></p>
<h3><strong>Working with Files under a Directory</strong></h3>
<p>Suppose that you want to list all BMP files under the f:\Pictures directory. You can write a code as shown in the code snippet given in Listing 3:</p>
<p><em><strong>Listing 3</strong></em></p>
<pre>DirectoryInfo dir = <span class="codeKeyword">new</span> DirectoryInfo(@"F:\WINNT");
FileInfo[] bmpfiles = dir.GetFiles("*.bmp);
Console.WriteLine("Total number of bmp files", bmpfiles.Length);
Foreach( FileInfo f in bmpfiles)
{
  Console.WriteLine("Name <span class="codeKeyword">is</span> : {0}", f.Name);
  Console.WriteLine("Length of the file <span class="codeKeyword">is</span> : {0}", f.Length);
  Console.WriteLine("Creation time <span class="codeKeyword">is</span> : {0}", f.CreationTime);
  Console.WriteLine("Attributes of the file are : {0}",
                     f.Attributes.ToString());
}</pre>
<h3><strong>Creating Subdirectories</strong></h3>
<p>You can easily create a subdirectory. Listing fragment 4 describes how to create a subdirectory called MySub under the Sub directory.</p>
<p><em><strong>Listing 4</strong></em></p>
<pre>DirectoryInfo dir = <span class="codeKeyword">new</span> DirectoryInfo(@"F:\WINNT");
<span class="codeKeyword">try</span>
{
  dir.CreateSubdirectory("Sub");
  dir.CreateSubdirectory(@"Sub\MySub");
}
<span class="codeKeyword">catch</span>(IOException e)
{
  Console.WriteLine(e.Message);
}</pre>
<h3><strong>Creating Files by Using the FileInfo Class</strong></h3>
<p>With the FileInfo class, you can create new files, access information about the files, delete, and move files. This class also provides methods for opening, reading from, and writing to a file. Listing 5 shows how to create a text file and access its information like its creation time, full name, and so forth.</p>
<p><em><strong>Listing 5</strong></em></p>
<pre>FileInfo fi = <span class="codeKeyword">new</span> FileInfo(@"F:\Myprogram.txt");
FileStream fstr = fi.Create();
Console.WriteLine("Creation Time: {0}",f.CreationTime);
Console.WriteLine("Full Name: {0}",f.FullName);
Console.WriteLine("FileAttributes: {0}",f.Attributes.ToString());

<span class="codeComment">//Way to delete Myprogram.txt file.</span>

Console.WriteLine("Press any key to delete the file");
Console.Read();
fstr.Close();
fi.Delete();</pre>
<h3><strong>Understanding the Open() Method</strong></h3>
<p>The FileInfo class defines a method named Open() with which you can create files by applying the values of the FileMode and FileAccess enumerations. The code snippet in Listing 6 describes its usage:</p>
<p><em><strong>Listing 6</strong></em></p>
<pre>FileInfo f = <span class="codeKeyword">new</span> FileInfo("c:\myfile.txt");
FileStream s = f.Open(FileMode.OpenorWrite, FileAccess.Read);</pre>
<p>You then can read from and write to a file by using the object &#8216;s&#8217;. In the overloaded Open() method, permission is given only for reading from a file. If you want to write to a file, you have to apply the ReadWrite value of FileAccess enumeration. Tables 4 and 5 describe the values of the FileMode and FileAccess enumerations.</p>
<table border="2" cellspacing="2" cellpadding="2">
<tbody>
<tr bgcolor="#ffff99">
<td valign="top"><strong>Values</strong></td>
<td valign="top"><strong>Purpose/Use</strong></td>
</tr>
<tr>
<td valign="top">Append</td>
<td valign="top">Opens the file and adds data. This should be used with the FileAccess Write Enumeration value.</td>
</tr>
<tr>
<td valign="top">Create</td>
<td valign="top">Creates a new file. Overwrites any existing file.</td>
</tr>
<tr>
<td valign="top">CreateNew</td>
<td valign="top">Creates a new file. If the file already exists, IOException is thrown.</td>
</tr>
<tr>
<td valign="top">Open</td>
<td valign="top">Opens an existing file</td>
</tr>
<tr>
<td valign="top">OpenOrCreate</td>
<td valign="top">Opens a new file. If there is no file, it creates a new file.</td>
</tr>
<tr>
<td valign="top">Truncate</td>
<td valign="top">Truncates an existing file</td>
</tr>
</tbody>
</table>
<p><em><strong>Table 4—FileMode Enumeration values</strong></em></p>
<table border="2" cellspacing="2" cellpadding="2">
<tbody>
<tr bgcolor="#ffff99">
<td valign="top"><strong>Values</strong></td>
<td valign="top"><strong>Purpose/Use</strong></td>
</tr>
<tr>
<td valign="top">Read</td>
<td valign="top">Data can be read (retrieved) from the file</td>
</tr>
<tr>
<td valign="top">ReadWrite</td>
<td valign="top">Data can be added to and retrieved from the file</td>
</tr>
<tr>
<td valign="top">Write</td>
<td valign="top">Data can be added to the file</td>
</tr>
</tbody>
</table>
<p><em><strong>Table 5—FileAccess Enumeration values</strong></em></p>
<h3><strong>Writing to a Text File by Using the StreamWriter Class</strong></h3>
<p>You can easily write texts or other information to a file by using the CreateText() method of the FileInfo class. However, you have to obtain a valid StreamWriter. It&#8217;s this StreamWriter reference that provides the required functionalities for writing to a file. To illustrate, Listing 7 writes a series of texts to the Mytext.txt file.</p>
<p><em><strong>Listing 7</strong></em></p>
<pre>FileInfo f = new FileInfo("Mytext.txt")
StreamWriter w = f.CreateText();
w.WriteLine("This is from");
w.WriteLine("Chapter 6");
w.WriteLine("Of C# Module");
w.<span class="codeKeyword">Write</span>(w.NewLine);
w.WriteLine("Thanks for your time");
w.<span class="codeKeyword">Close</span>();</pre>
<h3><strong>Reading from a Text File</strong></h3>
<p>You can read from a Text file by using the StreamReader class. For this, you have to specify the file name using the static OpenText() method of the File class. Listing 8 reads the contents that we have written in Listing 7:</p>
<p><em><strong>Listing 8</strong></em></p>
<pre>Console.WriteLine("Reading the contents from the file");
StreamReader s = File.OpenText("Mytext.txt");
<span class="codeKeyword">string</span> read = <span class="codeKeyword">null</span>;
<span class="codeKeyword">while</span> ((read = s.ReadLine()) != <span class="codeKeyword">null</span>)
{
  Console.WriteLine(read);
}
s.Close();</pre>
<h3><strong>About the Author</strong></h3>
<p>Anand Narayanaswamy works as a freelance Web/Software developer and technical writer. He runs and maintains learnxpress.com, and provides free technical support to users. His areas of interest include Web development, Software development using Visual Basic, and in the design and preparation of courseware, technical articles, and tutorials.</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/devarea.wordpress.com/7/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/devarea.wordpress.com/7/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/devarea.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/devarea.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/devarea.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/devarea.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/devarea.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/devarea.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/devarea.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/devarea.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/devarea.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/devarea.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/devarea.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/devarea.wordpress.com/7/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/devarea.wordpress.com/7/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/devarea.wordpress.com/7/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=7&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devarea.wordpress.com/2008/06/25/working-with-files-in-c/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9abeafc7358438edab347736f91998c9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bugmonster</media:title>
		</media:content>
	</item>
		<item>
		<title>Get File Extension Using C#</title>
		<link>http://devarea.wordpress.com/2008/06/25/get-file-extension-using-c/</link>
		<comments>http://devarea.wordpress.com/2008/06/25/get-file-extension-using-c/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 07:52:23 +0000</pubDate>
		<dc:creator>bugmonster</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Extension]]></category>
		<category><![CDATA[file]]></category>

		<guid isPermaLink="false">http://devarea.wordpress.com/?p=5</guid>
		<description><![CDATA[private string getFileExtension(string fileName) { string extension=””; char []arr=fileName.ToCharArray(); int index=0; for(int i=0;i&#60;arr.Length;i++) { if(arr[i]==’.’) { index=i; } } for(int x=index+1;x&#60;arr.Length;x++) { extension=extension+arr[x]; } return extension; }<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=5&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p><!--[if gte mso 10]&gt;--> <!--[endif]-->private string getFileExtension(string fileName)<br />
{</p>
<p style="text-indent:36pt;">string extension=””;</p>
<p style="text-indent:36pt;">char []arr=fileName.ToCharArray();</p>
<p style="text-indent:36pt;">int index=0;</p>
<p style="text-indent:36pt;">for(int i=0;i&lt;arr.Length;i++)</p>
<p style="text-indent:36pt;">{</p>
<p style="margin-left:36pt;text-indent:36pt;">if(arr[i]==’.’)</p>
<p style="margin-left:36pt;text-indent:36pt;">{</p>
<p style="margin-left:72pt;text-indent:36pt;">index=i;</p>
<p style="margin-left:36pt;text-indent:36pt;">}</p>
<p style="text-indent:36pt;">}</p>
<p style="text-indent:36pt;">for(int x=index+1;x&lt;arr.Length;x++)</p>
<p style="text-indent:36pt;">{</p>
<p style="margin-left:36pt;text-indent:36pt;">extension=extension+arr[x];</p>
<p style="text-indent:36pt;">}</p>
<p style="text-indent:36pt;">return extension;</p>
<p>}</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/devarea.wordpress.com/5/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/devarea.wordpress.com/5/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/devarea.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/devarea.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/devarea.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/devarea.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/devarea.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/devarea.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/devarea.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/devarea.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/devarea.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/devarea.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/devarea.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/devarea.wordpress.com/5/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/devarea.wordpress.com/5/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/devarea.wordpress.com/5/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=5&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devarea.wordpress.com/2008/06/25/get-file-extension-using-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9abeafc7358438edab347736f91998c9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bugmonster</media:title>
		</media:content>
	</item>
		<item>
		<title>How to loop through all files in a folder using C#</title>
		<link>http://devarea.wordpress.com/2008/06/25/how-to-loop-through-all-files-in-a-folder-using-c/</link>
		<comments>http://devarea.wordpress.com/2008/06/25/how-to-loop-through-all-files-in-a-folder-using-c/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 07:40:48 +0000</pubDate>
		<dc:creator>bugmonster</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[file]]></category>

		<guid isPermaLink="false">http://devarea.wordpress.com/?p=4</guid>
		<description><![CDATA[// How much deep to scan. (of course you can also pass it to the method) const int HowDeepToScan=4; public static void ProcessDir(string sourceDir, int recursionLvl) { if (recursionLvl&#60;=HowDeepToScan) { // Process the list of files found in the directory. string [] fileEntries = Directory.GetFiles(sourceDir); foreach(string fileName in fileEntries) { // do something with fileName [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=4&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>// How much deep to scan. (of course you can also pass it to the method)<br />
const int HowDeepToScan=4;</p>
<p>public static void ProcessDir(string sourceDir, int recursionLvl)<br />
{<br />
if (recursionLvl&lt;=HowDeepToScan)<br />
{<br />
// Process the list of files found in the directory.</p>
<p>string [] fileEntries = Directory.GetFiles(sourceDir);<br />
foreach(string fileName in fileEntries)<br />
{<br />
// do something with fileName<br />
Console.WriteLine(fileName);<br />
}</p>
<p>// Recurse into subdirectories of this directory.<br />
string [] subdirEntries = Directory.GetDirectories(sourceDir);<br />
foreach(string subdir in subdirEntries)<br />
// Do not iterate through reparse points<br />
if ((File.GetAttributes(subdir) &amp; FileAttributes.ReparsePoint) != FileAttributes.ReparsePoint)<br />
{<br />
ProcessDir(subdir,recursionLvl+1);<br />
}<br />
}<br />
}</p>
<p>Source: <a href="http://weblogs.asp.net/israelio/archive/2004/06/23/162913.aspx">weblogs.asp.net</a></p>
<p><span id="more-4"></span><br />
// Function: Get specified files (fileType) form sub-directory (sourceDir)<br />
// Return: void<br />
public void getJPGFromSubDir(string sourceDir, string fileType)<br />
{<br />
string[] dirEntries = Directory.GetDirectories(sourceDir);<br />
string fileName, filePath, fullFileName;</p>
<p>foreach (string subDir in dirEntries)<br />
{<br />
DirectoryInfo dir = new DirectoryInfo(subDir);<br />
FileInfo[] imgFiles = dir.GetFiles(fileType);</p>
<p>foreach (FileInfo imgFile in imgFiles)<br />
{<br />
fileName = imgFile.Name;<br />
filePath = imgFile.DirectoryName;<br />
fullFileName = filePath + &#8220;\\&#8221; + fileName;);<br />
}<br />
}<br />
}</p>
<br /><img alt="" border="0" src="http://feeds.wordpress.com/1.0/categories/devarea.wordpress.com/4/" /> <img alt="" border="0" src="http://feeds.wordpress.com/1.0/tags/devarea.wordpress.com/4/" /> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/devarea.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/devarea.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/devarea.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/devarea.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/devarea.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/devarea.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/devarea.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/devarea.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/devarea.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/devarea.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/devarea.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/devarea.wordpress.com/4/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/devarea.wordpress.com/4/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/devarea.wordpress.com/4/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=devarea.wordpress.com&amp;blog=4066291&amp;post=4&amp;subd=devarea&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://devarea.wordpress.com/2008/06/25/how-to-loop-through-all-files-in-a-folder-using-c/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/9abeafc7358438edab347736f91998c9?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">bugmonster</media:title>
		</media:content>
	</item>
	</channel>
</rss>
