tag:blogger.com,1999:blog-9083824352105358792024-03-05T17:10:49.418+05:30HardCodeDThis is where I get to teach codeJoel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.comBlogger15125tag:blogger.com,1999:blog-908382435210535879.post-68483741457892169192012-01-08T01:05:00.000+05:302012-03-25T01:11:13.082+05:30Get Web Browser History in C# - Google Chrome<span class="fullpost">
This post is a sort-of sequel to <a href="http://hardcodedblog.blogspot.in/2009/10/obtaining-browser-visited-url-history.html" target="_blank"> my previous blog post</a> on getting web browser history in C#. Google Chrome is the browser I had missed in the last blog post and I must say, it was quite interesting to code this up.
Just like Firefox, Chrome also uses an SQLite Database, but uses a structure quite different than that of Firefox. More details about it <a href="http://computer-forensics.sans.org/blog/2010/01/21/google-chrome-forensics/" target="_blank">here</a>.
As for Firefox, a very nice article is <a href="http://www.forensicswiki.org/wiki/Mozilla_Firefox_3_History_File_Format" target="_blank">here</a>.
Before you see the code, below are a few interesting points to note about Chrome:
<ol><li>The History file for Chrome is an SQLite database, but without the .sqlite extension. In fact, it does not have any extension. Its name is just History.</li><li>Google Chrome stores last visited times in UTC format. UTC time is basically the time elapsed since Jan 1, 1601. Unlike the UTC format for Windows file times which is in nanoseconds, Chrome stores the times in microseconds.</li>
<li>Also, the times are as per the GMT time zone. So, to get local times, TimeZoneInfo class provided by the .NET framework must be used.</li></ol>
Below is a tiny code snippet for getting Chrome history in C#:
</span>
<br />
<pre><div style="border: 0px solid rgb(0, 0, 128); font-family: Calibri,Georgia,Serif; font-size: 9pt;"><br /><div style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(221, 221, 221); max-height: 500px; overflow: auto;"><br /><ol style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(255, 255, 255); margin: 0pt 0pt 0pt 30px; padding: 0pt 0pt 0pt 0px;"><li><span style="color: blue;">public class</span> <span style="color: #2b91af;">HistoryItem</span></li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);">{</li><li> <span style="color: blue;">public string</span> URL { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"></li><li> <span style="color: blue;">public string</span> Title { <span style="color: blue;">get</span>; <span style="color: blue;">set</span>; }</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"></li><li> <span style="color: blue;">public</span> <span style="color: #2b91af;">DateTime</span> VisitedTime { get; set; }</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);">}</li><li></li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"><span style="color: blue;">static class</span> <span style="color: #2b91af;">Program</span></li><li>{</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: blue;">static void</span> Main()</li><li> {</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: blue;">string</span> chromeHistoryFile = <span style="color: #2b91af;">Environment</span>.GetFolderPath(<span style="color: #2b91af;">Environment</span>.SpecialFolder.LocalApplicationData))</li><li> + <span style="color: #a31515;">@"\Google\Chrome\User Data\Default\History"</span>;</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: blue;">if</span> (File.Exists(chromeHistoryFile))</li><li> {</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: #2b91af;">SQLiteConnection</span> connection = <span style="color: blue;">new</span> <span style="color: #2b91af;">SQLiteConnection</span></li><li> (<span style="color: #a31515;">"Data Source="</span> + chromeHistoryFile + <span style="color: #a31515;">";Version=3;New=False;Compress=True;"</span>);</li><li></li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> connection.Open();</li><li></li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: #2b91af;">DataSet</span> dataset = <span style="color: blue;">new</span> <span style="color: #2b91af;">DataSet</span>();</li><li></li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: #2b91af;">SQLiteDataAdapter</span> adapter = new <span style="color: #2b91af;">SQLiteDataAdapter</span></li><li> (<span style="color: #a31515;">"select * from urls order by last_visit_time desc"</span>, connection);</li><li> adapter.Fill(dataset);</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: blue;">if</span> (dataset != <span style="color: blue;">null</span> && dataset.Tables.Count > 0 & dataset.Tables[0] != <span style="color: blue;">null</span>)</li><li> {</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: #2b91af;">DataTable</span> dt = dataset.Tables[0];</li><li></li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> allHistoryItems = <span style="color: blue;">new</span> <span style="color: #2b91af;">List</span><<span style="color: #2b91af;">HistoryItem</span>>();</li><li></li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: blue;">foreach</span> (<span style="color: #2b91af;">DataRow</span> historyRow <span style="color: blue;">in</span> dt.Rows)</li><li> {</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: #2b91af;">HistoryItem</span> historyItem = <span style="color: blue;">new</span> <span style="color: #2b91af;">HistoryItem</span>();</li><li> {</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> URL = <span style="color: #2b91af;">Convert</span>.ToString(historyRow[<span style="color: #a31515;">"url"</span>]),</li><li>Title = <span style="color: #2b91af;">Convert</span>.ToString(historyRow[<span style="color: #a31515;">"title"</span>])</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> };</li><li></li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: green;">// Chrome stores time elapsed since Jan 1, 1601 (UTC format) in microseconds</span></li><li> <span style="color: blue;">long</span> utcMicroSeconds = <span style="color: #2b91af;">Convert</span>.ToInt64(historyRow[<span style="color: #a31515;">"last_visit_time"</span>]);</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"></li><li> <span style="color: green;">// Windows file time UTC is in nanoseconds, so multiplying by 10</span></li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: #2b91af;">DateTime</span> gmtTime = <span style="color: #2b91af;">DateTime</span>.FromFileTimeUtc(10 * utcMicroSeconds);</li><li></li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: green;">// Converting to local time</span></li><li> <span style="color: #2b91af;">DateTime</span> localTime = <span style="color: #2b91af;">TimeZoneInfo</span>.ConvertTimeFromUtc(gmtTime, <span style="color: #2b91af;">TimeZoneInfo</span>.Local);</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> historyItem.VisitedTime = localTime;</li><li></li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> allHistoryItems.Add(historyItem);</li><li> }</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> }</li><li> }</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"> }</li><li>}</li><li style="-moz-background-inline-policy: continuous; background: none repeat scroll 0% 0% rgb(243, 243, 243);"></li></ol></div></div></pre>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com33tag:blogger.com,1999:blog-908382435210535879.post-41808631959486027782010-01-12T10:40:00.034+05:302010-02-19T14:41:38.908+05:30Using extension methods in C#<img style="float: right; margin: 0pt 0pt 10px 10px; cursor: pointer; width: 244px; height: 288px;" src="http://blogs.msdn.com/blogfiles/jimoneil/WindowsLiveWriter/EisforExtensionMethod_1339D/e_2.gif" alt="" border="0" />One of the most exciting features of the .NET Framework is <a html="" com="">Extension Methods</a>. Extension methods allow you to extend the functionality of a class without modifying the code of the class itself. This allows you to write methods for a class anywhere outside the class. This is especially useful when there is no access to the code of the original class. For example, you can write a method to extend the <a html="" com="">System.String</a> class without actually changing the code of the System.String class. (You can't actually change the code of the System.String class) This method will be a static method residing in a static class anywhere in your application.<br /><span class="fullpost"><br />Extension methods are <a html="" com="">defined</a> as static methods, but are <a html="" com="">invoked</a> as instance methods. This is achieved by prefixing the <a html="" com="">this</a> keyword to the argument passed in the static method. For example, an extension method meant to remove vowels in a string would have a definition like:<pre><span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">string</span> RemoveVowels(<span style="color: rgb(0, 0, 255);">this</span> <span style="color: rgb(0, 0, 255);">string</span> str)<br /></pre> and it would be invoked as:<pre><div style="border: 1px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:10pt;"><br /><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous; max-height: 100px;"><br /><ol style="margin: 0pt 0pt 0pt 20px; padding: 0pt 0pt 0pt 5px; background: none repeat scroll 0% 0% rgb(255, 255, 255); -moz-background-inline-policy: continuous;"><li><span style="color: rgb(0, 0, 255);">string</span> str = <span style="color: rgb(163, 21, 21);">"Hello"</span>;</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);">string</span> newstr = str.RemoveVowels();</li></ol><br /></div></div></pre><br />A better, more complete example should make matters clearer. In an earlier <a href="http://hardcodedblog.blogspot.com/2009/07/files-and-folders.html" target="_blank">post</a>, the <a html="" com="">DirectoryInfo</a> class has been explained, and as has been pointed out, it does not have a method or property which returns its byte size unlike the <a html="" com="">FileInfo</a> class. So, one can write a method to extend the DirectoryInfo class as under:<br /><pre><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:9pt;"><br /><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous; max-height: 500px;"><ol style="margin: 0pt 0pt 0pt 20px; padding: 0pt 0pt 0pt 5px; background: none repeat scroll 0% 0% rgb(255, 255, 255); -moz-background-inline-policy: continuous;"><li><span style="color: rgb(0, 0, 255);">public static class</span> <span style="color: rgb(43, 145, 175);">ExtensionMethods</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;">{</li><li> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">long</span> GetSize(<span style="color: rgb(0, 0, 255);">this</span> <span style="color: rgb(43, 145, 175);">DirectoryInfo</span> dir)</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {</li><li> <span style="color: rgb(0, 128, 0);">// Initialize to zero</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">long</span> size = 0;</li><li><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Loop through all the subdirectories and files</span><br /></li><li> <span style="color: rgb(0, 0, 255);">foreach</span>(<span style="color: rgb(43, 145, 175);">DirectoryInfo</span> folder <span style="color: rgb(0, 0, 255);">in</span> dir.GetDirectories())</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> size += folder.GetSize(); <span style="color: rgb(0, 128, 0);">// Recursive call</span></li><li> <span style="color: rgb(0, 0, 255);">foreach</span>(<span style="color: rgb(43, 145, 175);">FileInfo</span> file <span style="color: rgb(0, 0, 255);">in</span> dir.GetFiles())</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> size += file.Length;</li><li><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">return</span> size;</li><li> }</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;">}</li></ol></div></div></pre><br />So one can use this method as an instance method of any DirectoryInfo instance.<br /><pre><div style="border: 1px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:10pt;"><br /><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous; max-height: 100px;"><br /><ol style="margin: 0pt 0pt 0pt 20px; padding: 0pt 0pt 0pt 5px; background: none repeat scroll 0% 0% rgb(255, 255, 255); -moz-background-inline-policy: continuous;"><li><span style="color: rgb(43, 145, 175);">DirectoryInfo</span> dir = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">DirectoryInfo</span>(<span style="color: rgb(163, 21, 21);">@"C:\WINDOWS"</span>);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);">long</span> sizeOfWindowsFolder = dir.GetSize();</li></ol><br /></div></div></pre><br />Visual Studio 2008 provides IntelliSense support for extension methods, which makes the job of using extension methods very easy. Programmers vary in opinion about the concept of extension methods with most programmers terming it as "advantageous" while some programmers terming it as "<a href="http://www.eggheadcafe.com/software/aspnet/31926605/extension-methods-in-net.aspx" target="_blank">a slap in the face of all serious software programmers</a>". I say, as is with everything in technology, it's all up to you, sir!<br /></span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com2tag:blogger.com,1999:blog-908382435210535879.post-67941825823908723872010-01-04T01:04:00.011+05:302010-03-18T12:23:21.722+05:30A brief introduction to WPF<img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 212px; height: 248px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEi_JLJLSW906qqHMH_r7pjCpQ15nG3lV_l8vcayiZN34du9BU2hi42CWn2xBQf0FiZWeEP2fOCJDF7HEBlkTH9Mnet5I-4XODyADFaDN2rzaIx9fAtX20zsoZa-Z7xgpTqkRUOj7i_BQo0/s320/wpf.png" alt="" id="BLOGGER_PHOTO_ID_5425567552585429122" border="0" />My previous post was an out-of-nowhere post on <a html="" com="">WPF (Windows Presentation Foundation)</a>, a technology not many developers know. Although you can easily know all there is to know "about" WPF on the web, learning to "use" WPF is more important and you need the proper resources for that. WPF applications can be developed in both Visual Studio 2008 and Expression Blend 2 and developing a complete WPF app requires expertise in both. Here are some resources which you can use:<br /><span class="fullpost"><br /><a href="http://joshsmithonwpf.wordpress.com/a-guided-tour-of-wpf/" target="_blank">A guided tour of WPF</a><br /><br /><a href="http://windowsclient.net/" target="_blank">The official WPF site</a><br /><br /><a href="http://msdn.microsoft.com/en-us/library/ms754130.aspx" target="_blank">The MSDN resource for WPF</a><br /><br />Here's my description of WPF:<br />WPF (Windows Presentation Foundation) is a programming model within the .NET Framework which allows you to build rich, compelling user interfaces. The highly-rated <a html="" com="">Silverlight</a> platform for the Web is nothing but a subset of WPF. You can compare it to Windows Forms, although there is a world of difference between the two. In fact, WPF is best understood when compared to WinForms.<br />In a WinForms app, there are 1 or more <a html="" com="">"forms"</a> which constitute the user interface. Each form is an instance of a class which derives from System.Windows.Forms.Form and its UI and codebehind are both in C#. So, there is a Form1.designer.cs and a Form1.cs both containing partial declarations of the class Form1.<br />In a WPF app, there are 1 or more <a html="" com="">"windows"</a> which constitute the interface. Each window is an instance of a class which derives from System.Windows.Window. While the codebehind is in C#, the UI is in what is called <a html="" com="">XAML (Extensible Application Markup Language)</a>. So, there is a Window1.xaml containing pure XAML and a Window1.xaml.cs containing pure C#, both containing partial declarations of the class Window1.<br />XAML is an HTML-style language which allows you to layout the controls of a window just as you would layout elements on an HTML page. XAML provides what WinForms cannot provide - rich and highly customizable user experiences. XAML provides for custom ListBoxes, binding controls to XML and CLR data sources, animations through storyboards and plenty more. In fact, you will get a better idea once you actually start creating a WPF app in Visual Studio 2008.<br />Apart from Visual Studio 2008, there is a software called <a html="" com="">Expression Blend 2</a> which allows you to concentrate only on the UI through XAML. Its intuitive interface allows you to do whatever you wish with the user interface. WPF is a very good and recommended thing to learn for developers. Code hard, go pro!<br /></span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com0tag:blogger.com,1999:blog-908382435210535879.post-61001865381573507952009-12-27T18:55:00.020+05:302010-04-23T19:32:54.413+05:30Visual inheritance in WPF<img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 192px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh1he00oW3V2grr6N2g6H37CG3ZDx_P8qSQmSmTfEynKkSxZgYTDDriMqBjPRUwr22ORFTny46mbG-fkqMemwuaH6G0DQGkjrD-_rFsR6S3Wn1zeB4C6v7ce22I-hQ3-nzNcHVCDn23WC8/s320/xamllogo.jpg" alt="" id="BLOGGER_PHOTO_ID_5422165438324632962" border="0" />My final year .NET project was a medium-weight WPF application which had some 8 windows in all. Creating the windows and customizing the interface in XAML was a breeze with <a html="" com="">Visual Studio 2008</a> and <a html="" com="">Expression Blend 2</a>. Even coding up the window logic was not that tough, but halfway into the logic part, I realized that all my windows had some properties and methods in common. So the code could be shortened a great deal using <a html="" com="">inheritance</a>.
<br /><span class="fullpost">
<br />Basically, the approach is simple. Create a class in a separate code file (say Blindow in Blindow.cs) which inherits from <a html="" com="">System.Windows.Window</a>, add all the properties and method implementations and virtual methods you need to it, and make all your windows inherit from Blindow. So, our Blindow looks like this:
<br /><pre><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:9pt;">
<br /><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous;">
<br /><ol style="margin: 0pt 0pt 0pt 20px; padding: 0pt 0pt 0pt 5px; background: none repeat scroll 0% 0% rgb(255, 255, 255); -moz-background-inline-policy: continuous;"><li><span style="color: rgb(0, 0, 255);">namespace</span> BlindApp.Windows</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;">{</li><li><span style="color: rgb(0, 0, 255);"> public</span> <span style="color: rgb(0, 0, 255);">class</span> <span style="color: rgb(43, 145, 175);">Blindow</span> : <span style="color: rgb(43, 145, 175);">Window</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {</li><li> <span style="color: rgb(0, 128, 0);">// all your properties and methods here</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> }</li><li>}</li></ol>
<br /></div>
<br /></div></pre>So, the class declarations for all the windows in the application now change from<pre><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:9pt;">
<br /><div style="background: none repeat scroll 0% 0% rgb(255, 255, 255); overflow: auto; -moz-background-inline-policy: continuous; max-height: 100px;"><span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">partial</span> <span style="color: rgb(0, 0, 255);">class</span> <span style="color: rgb(43, 145, 175);">Window1</span> : <span style="color: rgb(43, 145, 175);">Window</span>
<br /></div></div></pre>to<pre><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:9pt;">
<br /><div style="background: none repeat scroll 0% 0% rgb(255, 255, 255); overflow: auto; -moz-background-inline-policy: continuous; max-height: 100px;"><span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">partial</span> <span style="color: rgb(0, 0, 255);">class</span> <span style="color: rgb(43, 145, 175);">Window1</span> : <span style="color: rgb(43, 145, 175);">Blindow</span>
<br /></div></div></pre>
<br />All is fine and well, the code should compile correctly, but shockingly, it doesn't and throws up an error. Reason: Forgot the XAML. If you know WPF well, you must realize that the class declaration for Window1 in the codebehind is only <a html="" com="">partial</a>. The remaining partial declaration lies in the XAML. So, this means one has to come up with a way to let XAML know that Window1 inherits from Blindow now.
<br />The source of the error now lies here
<br />
<br /><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(255, 0, 0);">Window x</span><span style="color: rgb(0, 0, 255);">:</span><span style="color: rgb(255, 0, 0);">Class</span><span style="color: rgb(0, 0, 255);">="BlindApp.Windows.Window1"</span>
<br /><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span> <span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">:</span><span style="color: rgb(255, 0, 0);">x</span><span style="color: rgb(0, 0, 255);">="http://schemas.microsoft.com/winfx/2006/xaml"></span></div>
<br />
<br />So what we need to do to rectify the error is first add an XML namespace (with any name you like) for the CLR namespace. The CLR namespace for Window1 is BlindApp.Windows, so add a line as follows
<br />
<br /><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(255, 0, 0);">Window x</span><span style="color: rgb(0, 0, 255);">:</span><span style="color: rgb(255, 0, 0);">Class</span><span style="color: rgb(0, 0, 255);">="BlindApp.Windows.Window1"</span>
<br /><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span> <span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">:</span><span style="color: rgb(255, 0, 0);">x</span><span style="color: rgb(0, 0, 255);">="http://schemas.microsoft.com/winfx/2006/xaml"></span>
<br /><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">:</span><span style="color: rgb(255, 0, 0);">blinder</span><span style="color: rgb(0, 0, 255);">="clr-namespace:BlindApp.Windows"></span></div>
<br />
<br />You don't need to type out the <a html="" com="">clr-namespace:</a> statement - Visual Studio 2008 provides IntelliSense for that. But, we are not done yet, an error will again pop up because we need to replace the first line itself. Now that the XML namespace has been created, this is how it's done:
<br />
<br /><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);"><</span><span style="color: rgb(255, 0, 0);">blinder:Blindow x</span><span style="color: rgb(0, 0, 255);">:</span><span style="color: rgb(255, 0, 0);">Class</span><span style="color: rgb(0, 0, 255);">="BlindApp.Windows.Window1"</span>
<br /><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">="http://schemas.microsoft.com/winfx/2006/xaml/presentation"</span> <span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">:</span><span style="color: rgb(255, 0, 0);">x</span><span style="color: rgb(0, 0, 255);">="http://schemas.microsoft.com/winfx/2006/xaml"></span>
<br /><span style="color: rgb(255, 0, 0);">xmlns</span><span style="color: rgb(0, 0, 255);">:</span><span style="color: rgb(255, 0, 0);">blinder</span><span style="color: rgb(0, 0, 255);">="clr-namespace:BlindApp.Windows"></span></div>
<br />
<br />Just like you could set Resources and Triggers with Window.Resources and Window.Triggers, you can do the same now with <a html="" com=""><blinder:blindow.resources></a> and <a html="" com=""><blinder:blindow.triggers></a>
<br /></span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com0tag:blogger.com,1999:blog-908382435210535879.post-49387799399968907652009-12-20T17:42:00.033+05:302010-02-17T17:59:08.377+05:30MD5 and TripleDES encryption in .NET<img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 230px; height: 319px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEgoe3xxUEcNXdmtDClg3gCoQqIKqjoOu3KHPSf8Djqr-m3sc2DBpvJAA1W7nlFiONfE6xmb9SYmXuXlSyLUW5Dc9zszlNqMBbxXj_x9MlYvFpAKgYNdmFxvABtUove5aCS_VYs9_J2jpgI/s320/security01.jpg" alt="" id="BLOGGER_PHOTO_ID_5422170706807130962" border="0" />The .NET Framework provides classes for <a html="" com="">MD5 hashing</a> and <a html="" com="">TripleDES encryption</a>, both of which, when used together with a good enough key, form a good cryptographic system for your application. There are a lot of scenarios one can think of where encryption can be put to good use in both Desktop and Web applications. The following code snippet provides functions for encryption and decryption using MD5 and TripleDES.<br /><span class="fullpost"><br />What you need to include in the usings list is System.Security.Cryptography and System.Text and you are good to go. Making the functions static is just one of the best practices.<pre><br /><br /><br /><br /><br /><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:9pt;"><br /><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous; max-height: 500px;"><br /><ol style="margin: 0pt 0pt 0pt 20px; padding: 0pt 0pt 0pt 5px; background: none repeat scroll 0% 0% rgb(255, 255, 255); -moz-background-inline-policy: continuous;"><br /><li><span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> <span style="color: rgb(43, 145, 175);">Utils</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;">{</li><li> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">string</span> Encrypt(<span style="color: rgb(0, 0, 255);">string</span> toEncrypt, <span style="color: rgb(0, 0, 255);">string</span> key, <span style="color: rgb(0, 0, 255);">bool</span> useHashing)</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {</li><li> <span style="color: rgb(0, 128, 0);">// Convert both strings to byte arrays - you can use encoding other than UTF8</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">byte</span>[] keyArray = <span style="color: rgb(43, 145, 175);">UTF8Encoding</span>.UTF8.GetBytes(key);</li><li> <span style="color: rgb(0, 0, 255);">byte</span>[] toEncryptArray = <span style="color: rgb(43, 145, 175);">UTF8Encoding</span>.UTF8.GetBytes(toEncrypt);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> </li><li> <span style="color: rgb(0, 0, 255);">if</span> (useHashing)</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {</li><li> <span style="color: rgb(0, 128, 0);">// Hash the key</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">MD5CryptoServiceProvider</span> hashmd5 = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">MD5CryptoServiceProvider</span>();</li><li> keyArray = hashmd5.ComputeHash(keyArray);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> hashmd5.Clear();</li><li> }</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> </li><li> <span style="color: rgb(43, 145, 175);">TripleDESCryptoServiceProvider</span> tdes = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">TripleDESCryptoServiceProvider</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {</li><li> Key = keyArray,</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// The following line is controversial - follow the link below the snippet</span></li><li> Mode = <span style="color: rgb(43, 145, 175);">CipherMode</span>.ECB,</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> Padding = <span style="color: rgb(43, 145, 175);">PaddingMode</span>.PKCS7</li><li> };</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> </li><li> <span style="color: rgb(43, 145, 175);">ICryptoTransform</span> cTransform = tdes.CreateEncryptor();</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Transform and store in resultArray</span></li><li> <span style="color: rgb(0, 0, 255);">byte</span>[] resultArray = cTransform.TransformFinalBlock(toEncryptArray, 0, toEncryptArray.Length);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> tdes.Clear();</li><li> </li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(43, 145, 175);">Convert</span>.ToBase64String(resultArray, 0, resultArray.Length);</li><li> }</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> </li><li> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">string</span> Decrypt(<span style="color: rgb(0, 0, 255);">string</span> toDecrypt, <span style="color: rgb(0, 0, 255);">string</span> key, <span style="color: rgb(0, 0, 255);">bool</span> useHashing)</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {</li><li> <span style="color: rgb(0, 0, 255);">byte</span>[] keyArray = <span style="color: rgb(43, 145, 175);">UTF8Encoding</span>.UTF8.GetBytes(key);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">byte</span>[] toDecryptArray = <span style="color: rgb(43, 145, 175);">Convert</span>.FromBase64String(toDecrypt);</li><br /><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">if</span> (useHashing)</li><li> {</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">MD5CryptoServiceProvider</span> hashmd5 = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">MD5CryptoServiceProvider</span>();</li><li> keyArray = hashmd5.ComputeHash(keyArray);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> hashmd5.Clear();</li><li> }</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> </li><li> <span style="color: rgb(43, 145, 175);">TripleDESCryptoServiceProvider</span> tdes = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">TripleDESCryptoServiceProvider</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {</li><li> Key = keyArray,</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> Mode = <span style="color: rgb(43, 145, 175);">CipherMode</span>.ECB,</li><li> Padding = <span style="color: rgb(43, 145, 175);">PaddingMode</span>.PKCS7</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> };</li><br /><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">ICryptoTransform</span> cTransform = tdes.CreateDecryptor();</li><li> <span style="color: rgb(0, 0, 255);">byte</span>[] resultArray = cTransform.TransformFinalBlock(toDecryptArray, 0, toDecryptArray.Length);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> tdes.Clear();</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(43, 145, 175);">UTF8Encoding</span>.UTF8.GetString(resultArray);</li><li> }</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;">}</li></ol><br /></div><br /></div><br /></pre>FYI, <a href="http://www.codinghorror.com/blog/archives/001267.html" target="_blank">here is the controversy.</a><br />As you can see, both functions are quite similar except for precisely 2 lines. The <a html="" com="">Clear()</a> function on both occasions are required because <a html="" com="">MD5CryptoServiceProvider</a> and <a html="" com="">TripleDESCryptoServiceProvider</a> classes are "managed wrappers around unmanaged resources". Putting the Encrypt and Decrypt functions to use in your application would look like this:<pre><br /><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:9pt;"><div style="background: none repeat scroll 0% 0% rgb(255, 255, 255); overflow: auto; -moz-background-inline-policy: continuous; max-height: 100px;"><ol style="margin: 0pt; padding: 0pt 0pt 0pt 5px; background: none repeat scroll 0% 0% rgb(255, 255, 255); -moz-background-inline-policy: continuous;"><li><span style="color: rgb(0, 0, 255);">string</span> encrypted = <span style="color: rgb(43, 145, 175);">Utils</span>.Encrypt(<span style="color: rgb(163, 21, 21);">"Password"</span>, <span style="color: rgb(163, 21, 21);">"Key"</span>, <span style="color: rgb(0, 0, 255);">true</span>);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);">string</span> original = <span style="color: rgb(43, 145, 175);">Utils</span>.Decrypt(encrypted, <span style="color: rgb(163, 21, 21);">"Key"</span>, <span style="color: rgb(0, 0, 255);">true</span>);</li></ol><br /></div></div><br /></pre>Just make sure that you use the same key in both the lines, wherever the lines may be (they may be in two different applications referencing a common dll containing these functions) and the same hashing parameter as well. Happy encryption!</span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com1tag:blogger.com,1999:blog-908382435210535879.post-71147055387986640102009-11-23T12:10:00.030+05:302010-02-17T17:59:26.364+05:30Using FileUpload control in ASP.NET 2.0<img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 240px; height: 240px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhr5yfFm7VjWSXLVTwgTWk35vIlWzUznhLSMy2dpCBAYcqMtnD1dg1GMKAIQpYET2kDMT0Lc8rKvpFyam_yFWl7bf2PAn8UvyFVo3scCN01IVGhfU3Sh9JcgB9aIqCUsnpBVy9IWYq_DO0/s320/Upload_icon.jpg" alt="" id="BLOGGER_PHOTO_ID_5422593227764013426" border="0" />The <a html="" com="">FileUpload</a> control in ASP.NET 2.0 allows users to upload files onto the server. It is a familiar control on social networking sites and signup pages where users are required to upload images as profile photos or album pics. So, how exactly does one code up the process of uploading to the server? Read on.<br /><span class="fullpost"><br />The FileUpload control in ASP.NET 2.0 uploads the specified file at the specified path on the user's machine to a specified path on the web server. There are two approaches to this:<br /><ol><li><b><a html="" com="">SaveAs() method</a></b></li><br />The simpler, zero-effort approach is to use the SaveAs() method of the FileUpload control itself. What you need to do is write this single line of code in the event handler of the <a html="" com="">Upload</a> button on your WebForm.<pre><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:10pt;"><div style="background: rgb(255, 255, 255) none repeat scroll 0% 0%; overflow: auto; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; max-height: 500px;"><br /><div style="margin: 0pt 0pt 0pt 0px; padding: 0pt 0pt 0pt 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><br />fileupload1.SaveAs(<span style="color: rgb(163, 21, 21);">@"Uploads\"</span> + fileupload1.FileName);<br /></div></div></div></pre><br />The above code uploads the file to the <a html="" com="">Uploads</a> folder on the web server.<br /><br /><li><b><a html="" com="">HttpPostedFile object</a></b></li><br />The <a html="" com="">PostedFile</a> property of the FileUpload control returns an HttpPostedFile object which can be used to obtain additional information about the file uploaded such as length in bytes <a html="" com="">(ContentLength property)</a> and MIME type <a html="" com="">(ContentType property)</a>. It also returns a Stream object through its <a html="" com="">InputStream</a> property which is exactly the property useful in uploading. Take a look at the code.<pre><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:9pt;"><div style="background: rgb(221, 221, 221) none repeat scroll 0% 0%; overflow: auto; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; max-height: 500px;"><br /><ol style="margin: 0pt 0pt 0pt 30px; padding: 0pt 0pt 0pt 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><br /><li> <span style="color: rgb(43, 145, 175);">HttpPostedFile</span> uploadedFile = fileupload1.PostedFile;</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><br /></li><li> <span style="color: rgb(0, 128, 0);">// Read all data from the file into a byte array</span></li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);"> int</span> len = uploadedFile.ContentLength;</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">byte</span>[] data = <span style="color: rgb(0, 0, 255);">new byte</span>[len];</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> uploadedFile.InputStream.Read(data, 0, len);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><br /></li><li> <span style="color: rgb(0, 128, 0);">// Create a new file and stream the bytes to it</span></li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">FileStream</span> file = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">FileStream</span>(Server.MapPath(<span style="color: rgb(163, 21, 21);">@"Uploads\"</span> +<br /></li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> fileupload1.FileName, <span style="color: rgb(43, 145, 175);">FileMode</span>.Create);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> file.Write(data, 0 , len);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> file.Close();</li><br /></ol><br /></div></div></pre><br />The latter method is the one I invented because I had not known the SaveAs() method of the FileUpload control when I first used it. As for you, the choice is entirely in your hands.<br /></ol></span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com2tag:blogger.com,1999:blog-908382435210535879.post-11489472235374634932009-10-22T13:38:00.008+05:302010-02-17T17:59:48.298+05:30(Ab)using Registry classes in .NET<img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 320px; height: 222px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjqJM0oHqp1h7Qd1WTYb00GxxbJ0g1re-5VB9DHQPgumFYsW7wM8I_HQlj4j0bSq0aK6q3E2qTWC4trbzYH2ynk3iBfPV0BsEaai-Ft30Su9CVaMtI6fHpDzjCFiuBlB7IQoPNZmbOq5gY/s320/GUI.JPG" alt="" id="BLOGGER_PHOTO_ID_5353037550685532658" border="0" />The .NET Framework provides wonderful classes in the <a html="" com="">Microsoft.Win32 namespace</a> to read and write values to any key or set of keys in the <a html="" com="">Windows Registry</a>. These classes are not only wonderful but also dangerous because they have the potential to cause nasty and possibly irreversible changes to Windows. The following piece of code is DANGEROUS for your PC. So, do not run this code in your primary Windows Administrator account. Instead, create a dummy Windows Administrator account and run this code there. It's fun! And in fact there's so much else to do with the Registry!<br /><span class="fullpost">Create a Windows Console-based app in Visual Studio 2008 and copy the following code in the main Program.cs.<br /><br /><pre><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:9pt;"><div style="background: rgb(221, 221, 221) none repeat scroll 0% 0%; overflow: auto; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous; max-height: 500px;"><br /><ol style="margin: 0pt 0pt 0pt 30px; padding: 0pt 0pt 0pt 0px; background: rgb(255, 255, 255) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><br /><li><span style="color: rgb(0, 0, 255);">using</span> System;</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);">using</span> Microsoft.Win32;</li><li><br /></li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);">class</span> Program</li><li>{</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);"> static void</span> Main(<span style="color: rgb(0, 0, 255);">string</span>[] args)</li><li> {</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"WELCOME TO NASTY APPLICATION"</span>);</li><li> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"\nThis application will do the following:"</span>);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"1. Empty Start Menu"</span>);</li><li> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"2. Hide all drives"</span>);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"3. Clean Windows Explorer"</span>);</li><li> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"4. Enforce restrictions in Internet Explorer"</span>);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"5. Disable Task Manager"</span>);</li><li> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"\nPress any key to start"</span>);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">Console</span>.ReadKey();</li><li><br /></li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">using</span> (<span style="color: rgb(43, 145, 175);">RegistryKey</span> r1 = <span style="color: rgb(43, 145, 175);">Registry</span>.CurrentUser.CreateSubKey(<span style="color: rgb(163, 21, 21);">@"SOFTWARE\Microsoft\<br /> Windows\CurrentVersion\Policies\Explorer"</span>))</li><li> {</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"Emptying Start Menu..."</span>);</li><li> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoSMMyDocs"</span>, 1);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoSMMyPictures"</span>, 1);</li><li> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoStartMenuMyMusic"</span>, 1);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoStartMenuNetworkPlaces"</span>, 1);</li><li> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoStartMenuPinnedList"</span>, 1);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoStartMenuMFUprogramsList"</span>, 1);</li><li> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoFind"</span>, 1);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoControlPanel"</span>, 1);</li><li> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoStartMenuMorePrograms"</span>, 1);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoClose"</span>, 1);</li><li> r1.SetValue(<span style="color: rgb(163, 21, 21);">"StartMenuLogOff"</span>, 1);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoRun"</span>, 1);</li><li> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"Done"</span>);</li><li><br /></li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"Hiding all drives..."</span>);</li><li> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoViewOnDrive"</span>, 255);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoDrives"</span>, 255);</li><li> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"Done"</span>);</li><li><br /></li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"Cleaning Windows Explorer..."</span>);</li><li> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoTrayItemsDisplay"</span>, 1);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoDesktop"</span>, 1);</li><li> r1.SetValue(<span style="color: rgb(163, 21, 21);">"NoSetTaskbar"</span>, 1);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> r1.SetValue(<span style="color: rgb(163, 21, 21);">"HideClock"</span>, 1);</li><li> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"Done"</span>);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> }</li><li> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"Disabling Task Manager..."</span>);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> using (<span style="color: rgb(43, 145, 175);">RegistryKey</span> r2 = <span style="color: rgb(43, 145, 175);">Registry</span>.CurrentUser.CreateSubKey(<span style="color: rgb(163, 21, 21);">@"SOFTWARE\Microsoft\<br /> Windows\CurrentVersion\Policies\System"</span>))</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> {</li><li> r2.SetValue(<span style="color: rgb(163, 21, 21);">"DisableTaskMgr"</span>, 1);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> }</li><li> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"Done"</span>);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"Enforcing restrictions on IE..."</span>);</li><li> using (<span style="color: rgb(43, 145, 175);">RegistryKey</span> ie = <span style="color: rgb(43, 145, 175);">Registry</span>.CurrentUser.CreateSubKey(<span style="color: rgb(163, 21, 21);">@"SOFTWARE\Policies\Microsoft\<br /> Internet Explorer"</span>))</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> {</li><li> ie.CreateSubKey(<span style="color: rgb(163, 21, 21);">"Control Panel"</span>).SetValue(<span style="color: rgb(163, 21, 21);">"DisableDeleteBrowsingHistory"</span>, 1);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> ie.CreateSubKey(<span style="color: rgb(163, 21, 21);">"Control Panel"</span>).SetValue(<span style="color: rgb(163, 21, 21);">"FormSuggest Passwords"</span>, 1);</li><li> ie.CreateSubKey(<span style="color: rgb(163, 21, 21);">"Control Panel"</span>).SetValue(<span style="color: rgb(163, 21, 21);">"FormSuggest"</span>, 1);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> ie.CreateSubKey(<span style="color: rgb(163, 21, 21);">"Control Panel"</span>).SetValue(<span style="color: rgb(163, 21, 21);">"History"</span>, 1);</li><li> ie.CreateSubKey(<span style="color: rgb(163, 21, 21);">"LinksBar"</span>).SetValue(<span style="color: rgb(163, 21, 21);">"Enabled"</span>, 0);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> ie.CreateSubKey(<span style="color: rgb(163, 21, 21);">"Privacy"</span>).SetValue(<span style="color: rgb(163, 21, 21);">"EnableInPrivateBrowsing"</span>, 0);</li><li> ie.CreateSubKey(<span style="color: rgb(163, 21, 21);">"Privacy"</span>).SetValue(<span style="color: rgb(163, 21, 21);">"CleanHistory"</span>, 0);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> ie.CreateSubKey(<span style="color: rgb(163, 21, 21);">"Restrictions"</span>).SetValue(<span style="color: rgb(163, 21, 21);">"NoBrowserOptions"</span>, 1);</li><li> ie.CreateSubKey(<span style="color: rgb(163, 21, 21);">"Restrictions"</span>).SetValue(<span style="color: rgb(163, 21, 21);">"NoFavorites"</span>, 1);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> ie.CreateSubKey(<span style="color: rgb(163, 21, 21);">"Main"</span>).SetValue(<span style="color: rgb(163, 21, 21);">"Use FormSuggest"</span>, <span style="color: rgb(163, 21, 21);">"no"</span>);</li><li> }</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"Done!"</span>);</li><li><br /></li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"THANK YOU FOR YOUR PATIENCE"</span>);</li><li><br /></li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"A restart is necessary for the changes to take effect"</span>);</li><li> <span style="color: rgb(43, 145, 175);">Console</span>.WriteLine(<span style="color: rgb(163, 21, 21);">"\nPress any key to restart"</span>);</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"><br /></li><li> <span style="color: rgb(43, 145, 175);">Console</span>.ReadKey();</li><li style="background: rgb(243, 243, 243) none repeat scroll 0% 0%; -moz-background-clip: border; -moz-background-origin: padding; -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">Process</span>.Start(<span style="color: rgb(163, 21, 21);">"shutdown.exe"</span>, <span style="color: rgb(163, 21, 21);">"-r -t 00"</span>);</li><li> }</li><li>}</li><br /></ol></div></div></pre><br /><a html="" com="">Some explanation:</a> The program can be divided into 3 parts, one for each RegistryKey object r1, r2 and r3.<br /><br /><a html="" com="">r1</a> is the RegistryKey object which allows you to manipulate Windows Explorer any which way you like. r1 provides access to a Registry key whose values affect Start Menu, Taskbar, Control Panel and My Computer. For example, setting <a html="" com="">NoClose</a> value to 1 disables the Turn Off button on the Start Menu, <a html="" com="">NoFind</a> disables the Search button and <a html="" com="">NoRun</a> disables the Run button. The <a html="" com="">NoDrives</a> and <a html="" com="">NoViewOnDrive</a> keys deserve a bit more explanation. NoViewOnDrive makes drives disappear from My Computer, but the drives will be accessible elsewhere. NoDrives blocks access to the drives completely. The value passed to these keys determines the number and letters of drives affecte. Understand from this:<br />00000001 => 1 means only A: drive is affected.<br />00000011 => 3 means both A: and B: drives are affected.<br />00010100 => 20 means C: and E: drives are affected.<br />11111111 => 255 means all drives are affected.<br /><br /><a html="" com="">r2</a> is a relatively less significant RegistryKey object which prevents the Task Manager from appearing when Ctrl-Alt-Del is pressed.<br /><br /><a html="" com="">r3</a> is the RegistryKey object which allows you to customize Internet Explorer as per your requirements. The subkeys and their values set in the code are fairly self-explanatory. Some of them like InPrivate Browsing work only for IE 8.<br />After executing this code, if you want to review the changes in the Registry after running the code, comment out the <a html="" com="">NoRun</a> line so that you can open the Registry and undo the changes - However, as I have unfortunately discovered, not all changes can be undone, that's the reason why you are ADVISED to run this code on a dummy empty Administrator account!<br /></span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com0tag:blogger.com,1999:blog-908382435210535879.post-89925435802606322772009-10-03T18:50:00.046+05:302010-07-03T23:37:38.316+05:30Get Web browser history in C#<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUVLfgD-KWzg2ntwGTtgPu_czeHdVtl1GHWKj74Do1n5n79jUxZAuW9yfzEbyuWk0kRLyQL4ZMHtS0LghWty8sLML4q-YtdoOZyO-PZusKsWYNwHPERPpTNvAySb0QxIfi0gn1TtLs5Zg/s1600-h/history.jpg"><img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 225px; height: 284px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUVLfgD-KWzg2ntwGTtgPu_czeHdVtl1GHWKj74Do1n5n79jUxZAuW9yfzEbyuWk0kRLyQL4ZMHtS0LghWty8sLML4q-YtdoOZyO-PZusKsWYNwHPERPpTNvAySb0QxIfi0gn1TtLs5Zg/s320/history.jpg" alt="" id="BLOGGER_PHOTO_ID_5422169653963090802" border="0" /></a>In my final year .NET project, I had to code up a module to obtain the visited URL history of at least one web browser and delete some or all of the URLs from the history. A seemingly impossible job at first, I eventually managed to write (or rather get) some neat C# code for the purpose. Here is the outcome of some very good research.<br /><span class="fullpost"><br /><ol><li><b><a html="" com="">Internet Explorer</a></b></li><br />This was the easiest browser whose URL history can be obtained and deleted at will. My research started off with a Registry discovery - URLs typed in the address box of IE are captured in the Registry key <a html="" com="">HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\TypedURLs</a>. But that was way short of the purpose. Then, I came across the COM interface <a href="http://msdn.microsoft.com/en-us/library/ms774939%28VS.85%29.aspx" target="_blank">IUrlHistory on MSDN</a>. But it was COM and writing a C# class wrapper or something was something I was not proficient in at all. So, I reluctantly began searching for ready code. And voila!<br /><br /><a href="http://www.codeproject.com/KB/cs/ponta.aspx" target="_blank">An article on CodeProject</a> was all it took to serve my purpose. It provides a UrlHistoryLibrary.dll file which provides type-safe classes to access and manipulate IE's browsing history. Details on how to use the classes are given in the article itself. However, this is how I used it.<pre><br /><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:9pt;"><br /><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous; max-height: 500px;"><br /><ol style="margin: 0pt 0pt 0pt 30px; padding: 0pt 0pt 0pt 0px; background: none repeat scroll 0% 0% rgb(255, 255, 255); -moz-background-inline-policy: continuous;"><br /><li><span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> <span style="color: rgb(43, 145, 175);">InternetExplorer</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;">{</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 128, 0);"> // List of URL objects</span></li><li> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(43, 145, 175);">List</span><<span style="color: rgb(43, 145, 175);">URL</span>> URLs { <span style="color: rgb(0, 0, 255);">get</span>; <span style="color: rgb(0, 0, 255);">set</span>; }</li><li> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(43, 145, 175);">IEnumerable</span><<span style="color: rgb(43, 145, 175);">URL</span>> GetHistory()</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {</li><li> <span style="color: rgb(0, 128, 0);">// Initiate main object</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">UrlHistoryWrapperClass</span> urlhistory = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">UrlHistoryWrapperClass</span>();</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Enumerate URLs in History</span></li><li> <span style="color: rgb(43, 145, 175);">UrlHistoryWrapperClass</span>.<span style="color: rgb(43, 145, 175);">STATURLEnumerator</span> enumerator =<br /></li><li> urlhistory.GetEnumerator();</li><li><br /></li><li> <span style="color: rgb(0, 128, 0);">// Iterate through the enumeration</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">while</span> (enumerator.MoveNext())</li><li> {</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Obtain URL and Title</span></li><li> <span style="color: rgb(0, 0, 255);">string</span> url = enumerator.Current.URL.Replace(<span style="color: rgb(163, 21, 21);">'\''</span>, <span style="color: rgb(163, 21, 21);">' '</span>);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// In the title, eliminate single quotes to avoid confusion</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">string</span> title = <span style="color: rgb(0, 0, 255);">string</span>.IsNullOrEmpty(enumerator.Current.Title)</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> ? enumerator.Current.Title.Replace(<span style="color: rgb(163, 21, 21);">'\''</span>, <span style="color: rgb(163, 21, 21);">' '</span>) : <span style="color: rgb(163, 21, 21);">""</span>;</li><br /><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Create new entry</span></li><li> <span style="color: rgb(43, 145, 175);">URL</span> U = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">URL</span>(url, title, <span style="color: rgb(163, 21, 21);">"Internet Explorer"</span>);</li><br /><li> <span style="color: rgb(0, 128, 0);">// Add entry to list</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> URLs.Add(U);</li><li> }</li><br /><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Optional</span></li><li> enumerator.Reset();</li><br /><li> <span style="color: rgb(0, 128, 0);">// Clear URL History</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> urlhistory.ClearHistory();</li><br /><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">return</span> URLs;</li><li> }</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> }</li><br /></ol><br /></div><br /></div><br /></pre><b>Notes:</b><br />The code is fairly self-explanatory except for a few clarifications. The URL class used above is a simple class which has three string fields - URL, Title and BrowserName - and URLs is a <a html="" com="">List<code><</code>URL<code>></code></a>. Those little <a html="" com="">string.Replace</a> functions are to eliminate single quotes in the URLs so that there are no problems inserting them into an SQL database.<br /><br /><li><b><a html="" com="">Mozilla Firefox</a></b></li><br />The same thing for Mozilla Firefox was way tougher. First of all, it was difficult to locate where Firefox stores the browsing history. The answer came in the form of an SQLite database which is stored in the <a html="" com="">Application Data</a> of the Windows user. So, I had a SQLite database at hand. First, I tried <a html="" com="">FileStream</a> to the .sqlite file. I had opened the file in <a html="" com="">Notepad++</a> and seen that URLs were interspersed with quirky characters, so using the FileStream, I could manage to obtain the URLs, but obtaining the Titles was impossible. Moreover, I was never sure that a URL I come across was ever visited or was it a bookmark or what. So, again some code-googling later, I came across the <a html="" com="">ADO.NET Data Provider for SQLite</a>.The download page is <a href="http://sourceforge.net/projects/sqlite-dotnet2/" target="_blank">here.</a><br /><br />What is wonderful about this Provider is that not only it provided a .NET-native namespace (System.Data.SQLite), but also it provides full Visual Studio 2008 design-time support. So, without wasting more time, let me provide you the code.<pre><br /><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:9pt;"><br /><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous; max-height: 500px;"><br /><ol style="margin: 0pt 0pt 0pt 30px; padding: 0pt 0pt 0pt 0px; background: none repeat scroll 0% 0% rgb(255, 255, 255); -moz-background-inline-policy: continuous;"><br /><li><span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">class</span> <span style="color: rgb(43, 145, 175);">Firefox</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;">{</li><li> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(43, 145, 175);">List</span><<span style="color: rgb(43, 145, 175);">URL</span>> URLs { <span style="color: rgb(0, 0, 255);">get</span>; <span style="color: rgb(0, 0, 255);">set</span>; }</li><li> <span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(43, 145, 175);">IEnumerable</span><<span style="color: rgb(43, 145, 175);">URL</span>> GetHistory()</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {<br /></li><li> <span style="color: rgb(0, 128, 0);">// Get Current Users App Data</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">string</span> documentsFolder = <span style="color: rgb(43, 145, 175);">Environment</span>.GetFolderPath</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> (<span style="color: rgb(43, 145, 175);">Environment</span>.<span style="color: rgb(43, 145, 175);">SpecialFolder</span>.ApplicationData);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Move to Firefox Data</span></li><li> documentsFolder += <span style="color: rgb(163, 21, 21);">"\\Mozilla\\Firefox\\Profiles\\"</span>;</li><li><br /></li><li> <span style="color: rgb(0, 128, 0);">// Check if directory exists</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);"> if</span> (<span style="color: rgb(43, 145, 175);">Directory</span>.Exists(documentsFolder))</li><li> {</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 128, 0);"> // Loop each Firefox Profile</span></li><li><span style="color: rgb(0, 0, 255);"> foreach</span> (<span style="color: rgb(0, 0, 255);">string</span> folder <span style="color: rgb(0, 0, 255);">in</span> <span style="color: rgb(43, 145, 175);">Directory</span>.GetDirectories</li><li> (documentsFolder))</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {</li><li><span style="color: rgb(0, 128, 0);"> // Fetch Profile History</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);"> return</span> ExtractUserHistory(folder);</li><li> }</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> }</li><li><span style="color: rgb(0, 0, 255);"> return</span> <span style="color: rgb(0, 0, 255);">null</span>;</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> }</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">IEnumerable</span><<span style="color: rgb(43, 145, 175);">URL</span>> ExtractUserHistory(<span style="color: rgb(0, 0, 255);">string</span> folder)</li><li> {</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 128, 0);"> // Get User history info</span></li><li><span style="color: rgb(43, 145, 175);"> DataTable</span> historyDT = ExtractFromTable(<span style="color: rgb(163, 21, 21);">"moz_places"</span>, folder);</li><li><br /></li><li> <span style="color: rgb(0, 128, 0);">// Get visit Time/Data info</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(43, 145, 175);"> DataTable</span> visitsDT = ExtractFromTable(<span style="color: rgb(163, 21, 21);">"moz_historyvisits"</span>,<br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> folder);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Loop each history entry</span></li><li><span style="color: rgb(0, 0, 255);"> foreach</span> (<span style="color: rgb(43, 145, 175);">DataRow</span> row <span style="color: rgb(0, 0, 255);">in</span> historyDT.Rows)</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {</li><li><span style="color: rgb(0, 128, 0);"> // Select entry Date from visits</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);"> var</span> entryDate = (<span style="color: rgb(0, 0, 255);">from</span> dates <span style="color: rgb(0, 0, 255);">in</span> visitsDT.AsEnumerable()</li><li><span style="color: rgb(0, 0, 255);"> where</span> dates[<span style="color: rgb(163, 21, 21);">"place_id"</span>].ToString() == row[<span style="color: rgb(163, 21, 21);">"id"</span>].ToString()<br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);"> select</span> dates).LastOrDefault();</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// If history entry has date</span></li><li><span style="color: rgb(0, 0, 255);"> if</span> (entryDate != <span style="color: rgb(0, 0, 255);">null</span>)</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {</li><li><span style="color: rgb(0, 128, 0);"> // Obtain URL and Title strings</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);"> string</span> url = row[<span style="color: rgb(163, 21, 21);">"Url"</span>].ToString();</li><li><span style="color: rgb(0, 0, 255);"> string</span> title = row[<span style="color: rgb(163, 21, 21);">"title"</span>].ToString();</li><li><span style="color: rgb(0, 128, 0);"> <br /></span></li><li><span style="color: rgb(0, 128, 0);"> // Create new Entry</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(43, 145, 175);"> URL</span> u = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">URL</span>(url.Replace(<span style="color: rgb(163, 21, 21);">'\''</span>, <span style="color: rgb(163, 21, 21);">' '</span>),<br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> title.Replace(<span style="color: rgb(163, 21, 21);">'\''</span>, <span style="color: rgb(163, 21, 21);">' '</span>),</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(163, 21, 21);">"Mozilla Firefox"</span>);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Add entry to list</span></li><li> URLs.Add(u);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> }</li><li> }</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 128, 0);"> // Clear URL History</span></li><li> DeleteFromTable(<span style="color: rgb(163, 21, 21);">"moz_places"</span>, folder);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> DeleteFromTable(<span style="color: rgb(163, 21, 21);">"moz_historyvisits"</span>, folder);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);"><br /></span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><span style="color: rgb(0, 0, 255);"> return</span> URLs;</li><li> }</li><li> </li><li> <span style="color: rgb(0, 0, 255);">void</span> DeleteFromTable(<span style="color: rgb(0, 0, 255);">string</span> table, <span style="color: rgb(0, 0, 255);">string</span> folder)</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {</li><li> <span style="color: rgb(43, 145, 175);">SQLiteConnection</span> sql_con;</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">SQLiteCommand</span> sql_cmd;</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// FireFox database file</span></li><li> <span style="color: rgb(0, 0, 255);">string</span> dbPath = folder + <span style="color: rgb(163, 21, 21);">"\\places.sqlite"</span>;</li><li><br /></li><li> <span style="color: rgb(0, 128, 0);">// If file exists</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">if</span> (<span style="color: rgb(43, 145, 175);">File</span>.Exists(dbPath))</li><li> {</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Data connection</span></li><li> sql_con = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">SQLiteConnection</span>(<span style="color: rgb(163, 21, 21);">"Data Source="</span> + dbPath +<br /></li><li><span style="color: rgb(163, 21, 21);"> ";Version=3;New=False;Compress=True;"</span>);</li><li><br /></li><li> <span style="color: rgb(0, 128, 0);">// Open the Conn</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> sql_con.Open();</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Delete Query</span></li><li> <span style="color: rgb(0, 0, 255);">string</span> CommandText = <span style="color: rgb(163, 21, 21);">"delete from "</span> + table;</li><li><br /></li><li> <span style="color: rgb(0, 128, 0);">// Create command</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> sql_cmd = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">SQLiteCommand</span>(CommandText, sql_con);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> sql_cmd.ExecuteNonQuery();</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Clean up</span></li><li> sql_con.Close();</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> }</li><li> }</li><li><br /></li><li> <span style="color: rgb(43, 145, 175);">DataTable</span> ExtractFromTable(<span style="color: rgb(0, 0, 255);">string</span> table, <span style="color: rgb(0, 0, 255);">string</span> folder)</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> {</li><li> <span style="color: rgb(43, 145, 175);">SQLiteConnection</span> sql_con;</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">SQLiteCommand</span> sql_cmd;</li><li> <span style="color: rgb(43, 145, 175);">SQLiteDataAdapter</span> DB;</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(43, 145, 175);">DataTable</span> DT = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">DataTable</span>();</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// FireFox database file</span></li><li> <span style="color: rgb(0, 0, 255);">string</span> dbPath = folder + <span style="color: rgb(163, 21, 21);">"\\places.sqlite"</span>;</li><li><br /></li><li> <span style="color: rgb(0, 128, 0);">// If file exists</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">if</span> (<span style="color: rgb(43, 145, 175);">File</span>.Exists(dbPath))</li><li> {</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Data connection</span></li><li> sql_con = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">SQLiteConnection</span>(<span style="color: rgb(163, 21, 21);">"Data Source="</span> + dbPath +<br /></li><li><span style="color: rgb(163, 21, 21);"> ";Version=3;New=False;Compress=True;"</span>);</li><li><br /></li><li> <span style="color: rgb(0, 128, 0);">// Open the Connection</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> sql_con.Open();</li><li> sql_cmd = sql_con.CreateCommand();</li><li><br /></li><li> <span style="color: rgb(0, 128, 0);">// Select Query</span></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">string</span> CommandText = <span style="color: rgb(163, 21, 21);">"select * from "</span> + table;</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Populate Data Table</span></li><li> DB = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">SQLiteDataAdapter</span>(CommandText, sql_con);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> DB.Fill(DT);</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"><br /></li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 128, 0);">// Clean up</span></li><li> sql_con.Close();</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> }</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> <span style="color: rgb(0, 0, 255);">return</span> DT;</li><li> }</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243); -moz-background-inline-policy: continuous;"> }</li></ol><br /></div><br /></div><br /></pre>So, while some of this code was taken from the mozillazine forums, some was written on my own and the combination worked perfectly well for me in my final year project. Hope it works for you, too!<br /></ol><br /></span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com40tag:blogger.com,1999:blog-908382435210535879.post-85551556752938707082009-09-21T11:54:00.010+05:302009-09-21T20:39:00.278+05:30Best free addins for Visual Studio 2008<img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 227px; height: 184px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEiUgEHGwwjCU6qGFbETJrS6tsKjdpKfddbaoqvWC6QXw2FHLbV4FGdZIlsDPJExjPRe30-YypgdFoCl7ukr77_QA1yApJwXZpHObMPbqNfObdCujQuj0KZ9OG26ayiZ2_N_rS64yRhmzxA/s320/watermark.bmp" alt="Visual Studio 2008" title="Visual Studio 2008" id="BLOGGER_PHOTO_ID_5383936714335680386" border="0" />I have subscribed to the <a html="" com="">Microsoft Download Notifications</a> weekly newsletter and it was only yesterday that I clicked something which I had never clicked in any newsletter before - <a html="" com="">Visual Studio Gallery</a>. It is a list of addins - both free and free trials - for Visual Studio 2008 and if you are a .NET developer, you should not miss this!<br /><span class="fullpost"><br />Here's a list of the best 5 free addins I came across on that site. Hope you like them. Anyways, here's the site. <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/"><b>Visual Studio Addins Gallery.</b></a><br /><br /><ol><li><b><a html="" com="">Copy as HTML</a></b><br />Forget SyntaxHighlighter and all other online JavaScript tools you'd require to paste code in your blog without giving up all the indents and formatting. After installing this lightweight addin a "Copy as HTML" item is added to the context menu on code selection in VS 2008. The generated HTML can be played around with, so you can provide your own custom feel to the markup. The only issue is that it copies <code><</code> as <code>&lt;</code> and <code>></code> likewise. So copying XAML code is an issue.<br /></li><br /><li><b><a html="" com="">WPF NotifyIcon</a></b><br />This is the WPF equivalent of the WinForms NotifyIcon. With this, you do not need to initialize a system tray icon for your WPF application in code but in XAML itself.</li><br /><li><b><a html="" com="">WPF AboutBox</a></b><br />This is the WPF equivalent of the WinForms AboutBox. Detailed instructions on how to use it are available on the site itself.<br /></li><br /><li><b><a html="" com="">MRU Cleaner</a></b><br />This add-in allows you to manage the MRU (Most Recently Used) list of projects which can get irritatingly long and unwieldy in Visual Studio 2008. However, positive reviews of this add-in have not been forthcoming on the Add-In Gallery site, so here is an alternative download link.<br /><a href="http://www.csharper.net/blog/downloads.aspx">Download MRU Cleaner</a><br /></li><br /><li><b><a html="" com="">The CodeProject Add-In</a></b><br />Perhaps the best add-in in this list, the CodeProject add-in searches MSDN, CodeProject as well as the Web (Live Search) for articles based on what you enter in the search box. It may sound not too useful, but if you use it properly and to maximum advantage, you won't be able to code without it. Download link is here.<br /><a href="http://www.codeproject.com/Services/Addins/">Download The CodeProject Add-In</a><br /></li></ol><br /></span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com3tag:blogger.com,1999:blog-908382435210535879.post-13822277729143781972009-09-13T13:03:00.005+05:302009-10-07T00:15:56.565+05:30.NET ReflectorOccasionally, a .NET developer may feel the need to look through the <a html="" com="">source code</a> for .NET base class libraries to know exactly what goes on behind the scenes. Unfortunately, (as far as I know) <a html="" com="">Visual Studio 2008</a> does not permit that - it only provides an object browser that merely shows the class names and its properties and method signatures. Enter <a html="" com="">.NET Reflector</a>.<br /><br /><span class="fullpost">.NET Reflector is a <a html="" com="">free disassembler and analyzer tool</a> for all the classes in the .NET assemblies. It provides an accurate representation of the .NET base classes hierarchy and disassembles in multiple languages including<br /><br /><ul><li>C#</li><li>VB</li><li>IL</li><li>Chrome(!)</li><li>Delphi</li><li>MC++</li></ul>Besides showing Disassembly and Analysis in different panes, it has some pretty solid features like <a html="" com="">Search</a>, <a html="" com="">Options dialog</a>, <a html="" com="">MSDN Search</a> and <a html="" com="">Live Search</a> It also supports add-ins developed specifically for the Reflector which can be downloaded from <a html="" com="">CodePlex</a>. Download links for the Reflector and add-ins are below.<br /><br /><a href="http://www.red-gate.com/products/reflector/">Download Red Gate's .NET Reflector</a><br /><a href="http://reflectoraddins.codeplex.com/Wiki/View.aspx?title=Home">Download .NET Reflector Add-ins at CodePlex</a></span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com1tag:blogger.com,1999:blog-908382435210535879.post-35564201310232324952009-08-26T17:01:00.038+05:302010-04-14T01:13:32.974+05:30Classes for files and folders in C#The .NET Framework provides a comprehensive set of base classes to explore the entire file system, finding out files and folders that are present and listing their properties (and a whole lot of them). These base classes expose methods that allow file and folder operations as well, such as moving, copying, deleting and renaming. Here we go through the available classes.<br /><span class="fullpost"><br /><ol><li><b><a html="" com="">FileInfo and DirectoryInfo</a></b></li><br />These are non-static classes in the System.IO namespace that allow you to get almost any kind of information about files and folders and also allow operations like Deleting, Creating, Copying, Moving, etc. They are located in the System.IO namespace. Their constructors take a string that specifies the full path of the directory or file concerned.<div style="border: 0px solid rgb(0, 0, 128);font-family:'Courier New',Courier,Monospace;font-size:10pt;"><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous; max-height: 200px;"><ol style="margin: 0pt; padding: 0pt 0pt 0pt 5px; background: none repeat scroll 0% 0% rgb(255, 255, 255); -moz-background-inline-policy: continuous;"><li><br /><span style="color: rgb(43, 145, 175);">DirectoryInfo</span> main = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">DirectoryInfo</span>(<span style="color: rgb(163, 21, 21);">@"C:\hello"</span>);</li><li><span style="color: rgb(43, 145, 175);">FileInfo</span> main = <span style="color: rgb(0, 0, 255);">new</span> <span style="color: rgb(43, 145, 175);">FileInfo</span>(<span style="color: rgb(163, 21, 21);">@"C:\hello.txt"</span>);</li><br /></ol><br /></div></div><br />If the file or directory does not actually exist, <a html="" com="">an exception is not thrown</a> - just the <a html="" com="">Exists</a> property is set to false. Once the instance is set, one can read as well as write properties like <a html="" com="">LastAccessTime</a>, <a html="" com="">LastWriteTime</a>, <a html="" com="">CreationTime</a> and <a html="" com="">Attributes</a>. The methods of <a html="" com="">DirectoryInfo</a> class are more for the purpose of browsing through the file system while <a html="" com="">FileInfo</a> instances are more often used to open streams to the file in question. This may be the reason why DirectoryInfo lacks the <a html="" com="">Length</a> property of FileInfo which returns the size in bytes. One can write a tiny extension method for a DirectoryInfo instance:<br /><pre><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:9pt;"><br /><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous; max-height: 500px;"><ol style="margin: 0pt 0pt 0pt 20px; padding: 0pt 0pt 0pt 5px; background: none repeat scroll 0% 0% rgb(255, 255, 255); -moz-background-inline-policy: continuous;"><li><span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(0, 0, 255);">long</span> GetSize(<span style="color: rgb(0, 0, 255);">this</span> <span style="color: rgb(43, 145, 175);">DirectoryInfo</span> dir)</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243);">{</li><li> <span style="color: rgb(0, 0, 255);">long</span> length = 0;</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: rgb(0, 0, 255);">foreach</span> (<span style="color: rgb(43, 145, 175);">FileInfo</span> nextfile <span style="color: rgb(0, 0, 255);">in</span> dir.GetFiles())</li><li> length += nextfile.Exists ? nextfile.Length : 0;</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: rgb(0, 0, 255);">foreach</span> (<span style="color: rgb(43, 145, 175);">DirectoryInfo</span> nextdir <span style="color: rgb(0, 0, 255);">in</span> dir.GetDirectories())</li><li> length += nextdir.Exists ? nextdir.GetSize() : 0;</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: rgb(0, 0, 255);">return</span> length;</li><li>}</li></ol></div></div></pre><br />Although these classes can be used to move and copy files and folders, they are less preferable than the <a html="" com="">FileSystem</a> class which we'll discuss later in this post.<br /><br /><li><b><a html="" com="">DriveInfo</a></b></li><br />This class allows you to access any information about any drive in the machine. It is also located in the System.IO namespace. It provides a crucial single static method called <a html="" com="">GetDrives()</a> which returns all the drives in the machine as an array of DriveInfo instances. Each of the DriveInfo instances can then be used to obtain drive information in properties like <a html="" com="">AvailableFreeSpace</a>, <a html="" com="">TotalFreeSpace</a>, <a html="" com="">DriveFormat</a>, <a html="" com="">DriveType</a>, <a html="" com="">Name</a>, <a html="" com="">TotalSize</a> and <a html="" com="">VolumeLabel</a>. Perhaps the most important of these is the <a html="" com="">DriveType</a> property which is an enum that provides for as many as 7 drive types viz. <a html="" com="">CDRom</a>, <a html="" com="">Fixed</a>, <a html="" com="">Removable</a>, <a html="" com="">Network</a>, <a html="" com="">NoRootDirectory</a>, <a html="" com="">Ram</a> and <a html="" com="">Unknown</a>.<br />Here's a sample method to get names of all removable drives:<pre><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:9pt;"><br /><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous; max-height: 500px;"><ol style="margin: 0pt 0pt 0pt 20px; padding: 0pt 0pt 0pt 5px; background: none repeat scroll 0% 0% rgb(255, 255, 255); -moz-background-inline-policy: continuous;"><li><span style="color: rgb(0, 0, 255);">public</span> <span style="color: rgb(0, 0, 255);">static</span> <span style="color: rgb(43, 145, 175);">IEnumerable</span><<span style="color: rgb(0, 0, 255);">string</span>> GetRemovableDrives()</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243);">{</li><li> <span style="color: rgb(0, 0, 255);">return</span> <span style="color: rgb(0, 0, 255);">from</span> p <span style="color: rgb(0, 0, 255);">in</span> <span style="color: rgb(43, 145, 175);">DriveInfo</span>.GetDrives() </li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243);"> <span style="color: rgb(0, 0, 255);">where</span> p.DriveType == <span style="color: rgb(43, 145, 175);">DriveType</span>.Removable & p.IsReady == <span style="color: rgb(0, 0, 255);">true</span> </li><li> <span style="color: rgb(0, 0, 255);">select</span> p.Name;</li><li style="background: none repeat scroll 0% 0% rgb(243, 243, 243);">}</li></ol></div></div></pre><br /><li><b><a html="" com="">FileSystem class</a></b></li><br />This class allows you to move and copy files and folders. Though this can also be achieved with the DirectoryInfo and FileInfo classes as well, the difference is that FileSystem class hands over the transfer to the OS, so the OS provides the standard progress bar UI and the application can proceed normally. With the Info classes, the application is responsible for the transfer and so does not proceed to the next instruction until the transfer is complete, resulting in undesirable UI latency especially if the file or folder involved is large.<br /><pre><div style="border: 0px solid rgb(0, 0, 128);font-family:Calibri,Georgia,Serif;font-size:9pt;"><br /><div style="background: none repeat scroll 0% 0% rgb(221, 221, 221); overflow: auto; -moz-background-inline-policy: continuous; max-height: 500px;"><ol style="margin: 0pt 0pt 0pt 20px; padding: 0pt 0pt 0pt 5px; background: none repeat scroll 0% 0% rgb(255, 255, 255); -moz-background-inline-policy: continuous;"><li><span style="color: rgb(43, 145, 175);">FileSystem</span>.MoveDirectory(<span style="color: rgb(163, 21, 21);">@"C:\hello"</span>, <span style="color: rgb(163, 21, 21);">@"D:\hello"</span>, <span style="color: rgb(43, 145, 175);">UIOption</span>.AllDialogs);</li><li><span style="color: rgb(43, 145, 175);">FileSystem</span>.CopyDirectory(<span style="color: rgb(163, 21, 21);">@"C:\hello"</span>, <span style="color: rgb(163, 21, 21);">@"D:\hello"</span>, <span style="color: rgb(43, 145, 175);">UIOption</span>.AllDialogs);</li><li><span style="color: rgb(43, 145, 175);">FileSystem</span>.MoveFile(<span style="color: rgb(163, 21, 21);">@"C:\hello.txt"</span>, <span style="color: rgb(163, 21, 21);">@"D:\hello.txt"</span>, <span style="color: rgb(43, 145, 175);">UIOption</span>.AllDialogs);</li><li><span style="color: rgb(43, 145, 175);">FileSystem</span>.CopyFile(<span style="color: rgb(163, 21, 21);">@"C:\hello.txt"</span>, <span style="color: rgb(163, 21, 21);">@"D:\hello.txt"</span>, <span style="color: rgb(43, 145, 175);">UIOption</span>.AllDialogs);</li></ol></div></div></pre><br />It is located in a completely disparate <a html="" com="">Microsoft.VisualBasic.FileIO</a> namespace.<br />Other than just transferring files and folders, the FileSystem class provides in fact a wide range of static methods that emulate the behavior of other classes like FileStream, FileInfo and DirectoryInfo. A quick <a href="http://msdn.microsoft.com/en-us/library/microsoft.visualbasic.fileio.filesystem_methods%28VS.80%29.aspx" target="_blank">view</a> and you'll know what I mean.<br /></ol><br />So, I suppose I covered all the .NET classes for Directories and Files. I hope it is useful to you!</span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com2tag:blogger.com,1999:blog-908382435210535879.post-61526679406702635742009-07-15T17:39:00.002+05:302010-02-17T18:01:30.038+05:30Everything is a class!It is amazing how often I need to remind my friends with programming doubts that C# is object-oriented - there is no line of code in C# without a reference to a class or an object. There is a class for almost everything in the .NET Framework and its interoperability features make it the platform of choice for Windows applications.<br /><br /><span class="fullpost">And C# is just the right language for .NET. Although people have tried to convince me that VB.NET is also completely object-oriented, it just does not seem to be a true programmer's language of choice. Never mind the syntax, the lack of braces and the presence of keywords like <a html="" com="">My.Computer</a> (!) make it simply an uncomfortable language to work with especially for a programmer with C background.<br /><br />Coming back to my friends, I had a friend calling me yesterday with a <a html="" com="">DataGridView</a> problem. He said he had a form (say Form1) on which if the user clicked a button, the DataGridView should display all the relevant data. The guy had made the button-click event handler to invoke a method from another class (say Class1) which is fine as he meant to segregate the UI classes from the database classes. The problems are here <ul><li>The method initialized and filled a DataGridView which was a property of Class1.</li><li>The method returned void.</li><li>The method was called in the button-click event handler from an instance of Class1.</li></ul>His code would look like<br /><pre><code><br />class Form1<br />{<br />......<br />...<br />private void Button1_Click(object sender, RoutedEventArgs e)<br />{<br /> Class1 obj = new Class1();<br /> obj.FillMyGridView();<br />}<br />.....<br />}<br />// The following class in another file, in another namespace<br />class Class1<br />{<br />......<br />...<br />public DataGridView Grid{ get; set;}<br /><br />public void FillMyGridView()<br />{<br /> Grid = // initialize and fill Grid<br />}<br />}<br /></code></pre><br />Now whether you are laughing at the guy already or empathizing with him depends on which level programmer you are. I told him that a void-returning method just won't do. Although I fairly convinced him why, he was just reluctant to make a method that returned a DataGridView or a even a DataBindingSource to the form.<br />Nevertheless, he had a keenness to learn and that is what, I feel, any programmer should have. Never be ashamed of what you do not know - there is always more to know no matter how much you already know and there is always a guy who knows less than you do.<br /></span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com0tag:blogger.com,1999:blog-908382435210535879.post-15297220219806005922009-07-04T20:02:00.000+05:302009-09-05T13:17:37.277+05:30All is fair in love and var<img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 223px; height: 140px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEh2Hz7O0LYqJJaSZJ_hixldsij3grWPjGlWDEX6-knfXzy02z8Y_m7HGRG_vuPa_s1qt0T4WOOBjJRV-KDJ7sSdFA36THPEEBV941KnjzDC-G8FXPyApP84jZtoayqCJpGBm3Btw5uO8dg/s320/var.jpg" alt="" id="BLOGGER_PHOTO_ID_5377884857037568738" border="0" />The <a>var</a> keyword in <a com="">C# 3.0</a> has been the subject of much <a href="http://www.codeproject.com/Lounge.aspx?msg=3166626#xx3166626xx">scorn</a> recently, which I feel is uncalled for.<span class="fullpost"> It is really a matter of personal preference - I use the var keyword in <span style="font-weight: bold;">LINQ</span> queries, and I think there's no other good way of storing the output of a LINQ query. <span style="font-weight: bold;">Implicit typing</span> is just an equally strong typing convention as explicit typing as the compiler determines the actual type, never so wrongly.<br /><br /><span style="font-weight: bold;">Anonymous types</span> are, to me, a blessing of LINQ, and there's no better way to save variables of anonymous types than in a var. Using the var keyword in any context other than LINQ, however, would be undesirable, as readability can be compromised and the code would unnecessarily be cluttered.<br /></span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com1tag:blogger.com,1999:blog-908382435210535879.post-55413233889685001812009-06-28T17:56:00.008+05:302009-09-02T20:29:09.264+05:30My first CP paper<a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivTvuvrBoHM_SW7WTW_SOV55Aktw0U5B8wLrs8YmFbFN-T9_SsIcz-dhnGvIkllxHx7PX2_DdIVX_r9N-R4LT5bud5ESIXBTgYntilAA8xNhSDJ7zz-5YAJquJbjMLPE8k6lKPzzyRF4M/s1600-h/code.jpg"><img style="margin: 0pt 0pt 10px 10px; float: right; cursor: pointer; width: 231px; height: 178px;" src="https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEivTvuvrBoHM_SW7WTW_SOV55Aktw0U5B8wLrs8YmFbFN-T9_SsIcz-dhnGvIkllxHx7PX2_DdIVX_r9N-R4LT5bud5ESIXBTgYntilAA8xNhSDJ7zz-5YAJquJbjMLPE8k6lKPzzyRF4M/s320/code.jpg" alt="" id="BLOGGER_PHOTO_ID_5376884436994874786" border="0" /></a>I went through the ruins in my table today and found and tore away many useless things - hall tickets, application forms, document copies, etc. They were all taking up precious little space and my mind felt lighter with all of them gone - they brought back memories and I am tired of memorizing!<br /><br />One thing which caught my attention was the <a com="" html="">CP question paper</a> of my First Semester in Engineering. <span class="fullpost">CP was a particularly tough paper back then, it was compulsory for all branches of Engineering (<span style="font-style: italic;"><a com="" html="">one of the very grave follies of the University because of which even Mechanical and Civil Engineering students had to go through it</a></span>) and the language was <a com="" html="">C</a> - <a com="" html="">Turbo C</a> to be precise.<br /><br />The programs in the first question were about computing <a com="" html="">compound interest</a> and Ackerman's <(<span style="font-style: italic;">yes, they had spelled it wrong</span>) function - a good testing combo for a compulsory question (<span style="font-style: italic;">Many wished it were easier!</span>). This was the first time I had seen the <a com="" html="">Ackermann's function</a> and the question had mentioned it was popular with lecturers and students of Computer Science! I finished them with ease and moved on to the next question.<br /><a com="" html="">Expected score: 15 out of 20</a><br /><br />The programs in the second question were about finding four-digit perfect squares which are concatenations of two-digit perfect squares (e.g. 1681) and a weird <a com="" html="">convergence-to-1 algorithm</a>.<br />The algorithm goes like this<br /><ul><li>If the number is odd, multiply by 3 and add 1.</li><li>If the number is even, divide by 2.</li><li>Repeat until number is 1.</li></ul>Both were pieces of cake which I ate in a jiffy and went to the next question.<br /><a com="" html="">Expected score: 16 out of 20</a><br /><br />The programs in the third question were about neat tabular display of marks of 50 students and computing <a com="" html="">mean, variance and standard deviation</a> (The formulas for each of them were given!). Again, good for me, but surprisingly, it was taking longer than expected because it was the first time I was writing full-fledged programs. My answer-sheet was getting dirtier with scribblings, cancellations, so I resorted to rough work.<br /><a com="" html="">Expected score: 14 out of 20</a><br /><br />The programs in the fourth question were <a com="" html="">tricky</a> - a program to compute and display tip speeds for a set of shank speeds against an input value of diameter (Whoa!) and a program to find <a com="" html="">minimax</a> values in a 2-D array. It took a while for me to comprehend the first question though it turned out to be a simple program, but the second program caught me - I was not particularly good at functions at the time and this program had to do exactly that. So, I took an arduous, far less intuitive way out and the program turned out to be so large, I was assured it would not fetch me any marks!<br /><a com="" html="">Expected score: 10 out of 20</a><br /><br />The programs in the fifth question were about <a com="" html="">structures</a> - a point structure program and an employee structure program. The employee structure program was long as it required <a com="" html="">searching and sorting</a>. Good, but time-consuming.<br /><a com="" html="">Expected score: 13 out of 20</a><br /><br />So, I <a com="" html="">expected 68</a> out of a good first-time CP paper. I could be more intuitive with the programs, but for lack of time. Many others had struggled, because they expected "standard" programs and not out-of-the-box ones. The results came out later and many failed (CP is tough for many, even in IT and CS streams!), and I <a com="" html="">scored 45</a> - dismal and pathetic compared to my expectations. I applied for revaluation, but nothing came through it. I never got discouraged though - I had found programming interesting and fun, and I felt I had chosen the perfectly right career path. I have the copy of my answer-sheet with me till now, which I read through sometimes to brush up on programming basics!</span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com2tag:blogger.com,1999:blog-908382435210535879.post-21505194402549243392009-06-25T15:51:00.003+05:302009-08-28T20:24:47.354+05:30.NET Framework - an addiction<div style="text-align: justify;">I seriously <span style="font-weight: bold;">do not know</span> Java. No matter how much I try, I have never managed to code up a page in Java, let alone an entire application. On the other hand, my first application in .NET was so quick and easily done that I felt I am a .NET pro since ages!</div><span class="fullpost">The first languages I learned were <span style="font-weight: bold;">HTML and ASP-VBScript</span>, and I never managed to come out of the Web markup mode for quite some time.<br /><br />I have <span style="font-weight: bold;">Eclipse</span> and <span style="font-weight: bold;">JCreator</span> installed at home - the Add or Remove Programs list terms them as 'rarely' used. The first programming language I learnt was <span style="font-weight: bold;">C</span> and believe me, C is beautiful. All the includes, conditions, loops, functions, structs, arrays, pointers got me hooked on to C big time and I thought C is the best language in the world. Then came C++, and OOP was revealed to me. For some time, I still preferred C, but eventually, for want of better programming experience, I embraced C++.<br /><br />Java was introduced to me after a considerable period of time, and frankly, I never got round to it. Java was never meant for me and it always took me quite some time to code up a line. I always felt there must be something like Java, yet different from it. This is certainly not it.<br /><br />And then came the big one -<span style="font-weight: bold;"> C#</span>. It was just C all grown up, and I forgot all about Java. I must thank <span style="font-weight: bold;">Visual Studio 2008</span> here for introducing me to all the beauties of C#, and believe me, Visual Studio 2008 is a great IDE. I could have used it to learn VB (mind you, VB 2008 is not <span style="font-weight: bold;">IN ANY WAY</span> like VB 6 of old), but I preferred C# due to my firm grounding in C and C++. The environment allowed me to learn C# well and fast, and applications were developed in no time. In fact, my final year project was <span style="font-weight: bold;">a dazzling WPF application</span>, which was supposed to be developed over a year, but being the quintessential engineering student, I started in the last 2 weeks and finished it just before the deadline. After all, the .NET Framework is just meant for <span style="font-weight: bold;">RAD (Rapid Application Development)</span>.<br /><br /><div style="text-align: justify;">Microsoft managed to <span style="font-weight: bold;">wean away</span> many Java developers like me towards the .NET Framework, not just because it gained significant mileage over a short period of time, but because it has some <span style="font-weight: bold;">sound principles</span> running behind it, original and otherwise. <span style="font-weight: bold;">Platform Independence</span> through Intermediate Language, <span style="font-weight: bold;">Garbage Collection</span>, <span style="font-weight: bold;">Language Interoperability</span> are just some of the principles guiding the .NET Framework and they go a long way in keeping developers loyal to .NET. However, the .NET Framework is so popular maybe only because of the Visual Studio, an excellent IDE which has evolved from its 2005 version to its 2008 version as the .NET Framework has evolved from its 2.0 version to 3.5. With new technologies like <span style="font-weight: bold;">WPF, WCF, LINQ and WF</span> (of which I have 'mastered' WPF as yet) in its latest 3.5 version, .NET is indeed attractive.<br /></div>(.NET 4.0 and correspondingly, Visual Studio 2010 to be released later this year)<br /><br />Java is still preferred by the <span style="font-weight: bold;">'pure' programmers</span> - people who require complete control over each and every aspect of their application and leave nothing at the mercy of their IDE. That is precisely the reason why Java does not assist much in laying out a good UI for your application - Java programmers still grapple with the SetBounds function for different UI elements in their application. .NET, on the other hand, just says, Do not stress yourself out, lemme help you! .NET is as powerful as Java, but easier to learn and more addictive than Java.</span>Joel Mathiashttp://www.blogger.com/profile/15202879162733377230noreply@blogger.com1