<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>BradVin's .Net Blog</title><link>https://weblogs.asp.net:443/bradvincent/</link><description>Code, snippets, controls, utils, etc. Basically all things .net
&lt;p&gt;&lt;a href="http://feeds.feedburner.com/BradVinsDotNetBlog"&gt;&lt;img src="http://feeds.feedburner.com/~fc/BradVinsDotNetBlog?bg=660033&amp;amp;fg=FFFFFF&amp;amp;anim=0" height="26" width="88" style="border:0" alt="" /&gt;&lt;/a&gt;&lt;/p&gt;</description><item><title>Squashing the asp.net MVC response - part 1</title><link>https://weblogs.asp.net:443/bradvincent/squashing-the-asp-net-mvc-response-part-1</link><description>&lt;p&gt;&lt;b&gt;The goal of this post&lt;/b&gt; : reduce the total size of a simple asp.net MVC page response.&lt;br&gt;&lt;b&gt;Our measuring tools&lt;/b&gt; : Firefox running &lt;a href="http://getfirebug.com" target="_blank" mce_href="http://getfirebug.com"&gt;Firebug&lt;/a&gt; and the &lt;a href="http://developer.yahoo.com/yslow/" target="_blank" mce_href="http://developer.yahoo.com/yslow/"&gt;YSlow plugin&lt;/a&gt;&lt;br&gt;&lt;b&gt;Source Code&lt;/b&gt; : &lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Code/MVCSquash1.zip"&gt;Download here&lt;br&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Lets use a really simple and common scenario as the example. The steps to create this really simple example are:&lt;br&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create a new MVC project in visual studio.&lt;/li&gt;

&lt;li&gt;Dump some useful script files into the scripts folder and delete the others we dont need.&lt;/li&gt;

&lt;li&gt;Create a new .css file in the Content folder and cut half the css out of the site.css and paste it into this new file. (this is just to create more than 1 css file)&lt;br&gt;&lt;/li&gt;

&lt;li&gt;Open the site.master file and add references to the new files in the head.&lt;br&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Why are we doing this? Well this is what you would most likely do when adding functionality to your new MVC site. You would add a few references to some scripts you will use in the views, and you would more than likely add some references to more css files. (I personally hate combining css into one large file, and instead prefer to break it up into logical files)&lt;br&gt;&lt;br&gt;The resulting site.master would look something like this:&lt;/p&gt;


&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Master Language="C#" Inherits="System.Web.Mvc.ViewMasterPage" %&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;PUBLIC&lt;/span&gt; &lt;span class="kwrd"&gt;"-//W3C//DTD XHTML 1.0 Strict//EN"&lt;/span&gt; &lt;span class="kwrd"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:ContentPlaceHolder&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="TitleContent"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;link&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;="../../Content/Site.css"&lt;/span&gt; &lt;span class="attr"&gt;rel&lt;/span&gt;&lt;span class="kwrd"&gt;="stylesheet"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/css"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;link&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;="../../Content/Layout.css"&lt;/span&gt; &lt;span class="attr"&gt;rel&lt;/span&gt;&lt;span class="kwrd"&gt;="stylesheet"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/css"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;="../../Scripts/jquery-1.3.2.js"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &amp;lt;script src=&lt;span class="str"&gt;"../../Scripts/jquery.utils.js"&lt;/span&gt; type=&lt;span class="str"&gt;"text/javascript"&lt;/span&gt;&amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;    &amp;lt;script src=&lt;span class="str"&gt;"../../Scripts/jqDnR.js"&lt;/span&gt; type=&lt;span class="str"&gt;"text/javascript"&lt;/span&gt;&amp;gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt; &lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;-&lt;/span&gt; &lt;span class="attr"&gt;extracted&lt;/span&gt; &lt;span class="attr"&gt;--&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;
Let's compile and run the MVC site. Open it in FireFox. Turn on firebug and see what u get. I got this Net breakdown:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/firebug1.gif"&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/firebug1.gif" border="0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note at this stage the number of requests (6) and the total download size (135KB) and it took 4.11 seconds. Also notice that when you refresh the page, ALL the page components are downloaded AGAIN. Nothing is cached. This is not good. Now the YSlow breakdown :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/yslow1.gif"&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/yslow1.gif" border="0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;nbsp;See our YSLOW score is 73!! WOW thats bad. You can expand each section to see exactly what you can do to improve the performance. Here it is expanded :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/yslow2.gif"&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/yslow2.gif" border="0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we are going to work through the page to improve our YSlow score and our overall download size. In this post I am going to go straight into the solution. I will use future posts to explain the code behind the changes and the reasons why I did what I did. I am also going to be using both code I have found on the web and some code I have written myself (with some ideas taken from the web). Again, all my code will be explained in future posts. This post is just an intro while giving a solution. (cause I hate blog series where you have to wait untill the last one to get the solution, especially seeing that I write about 1 post every 6 months - i promise i will try harder!)&lt;/p&gt;

&lt;p&gt;I have put all the source together into my own Utils components. I have spoken about these a while ago and they have changed dramatically since then. There are 4 files you need to reference from the web project :&lt;br&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="http://www.codeplex.com/unity" target="_blank" mce_href="http://www.codeplex.com/unity"&gt;Unity&lt;/a&gt; - Dependency injection framework used by the utils project&lt;/li&gt;

&lt;li&gt;Utils - common utils and helper classes incl. &lt;a href="/bradvincent/archive/2007/10/07/220-berutils-part-1-cryptography-continued.aspx" target="_blank" mce_href="/bradvincent/archive/2007/10/07/220-berutils-part-1-cryptography-continued.aspx"&gt;encryption&lt;/a&gt; wrappers, &lt;a href="/bradvincent/archive/2007/12/13/220-berutils-part-4-collections.aspx" target="_blank" mce_href="/bradvincent/archive/2007/12/13/220-berutils-part-4-collections.aspx"&gt;collections&lt;/a&gt;, &lt;a href="/bradvincent/archive/2007/10/22/220-berutils-part-3-strings.aspx" target="_blank" mce_href="/bradvincent/archive/2007/10/22/220-berutils-part-3-strings.aspx"&gt;string utils&lt;/a&gt;, a number of extension methods, etc etc&lt;/li&gt;

&lt;li&gt;Utils.Web - common web utils and helpers not specific to either webforms or MVC incl &lt;a href="/bradvincent/archive/2008/10/27/helper-class-querystring-builder-chainable.aspx" target="_blank" mce_href="/bradvincent/archive/2008/10/27/helper-class-querystring-builder-chainable.aspx"&gt;querystring&lt;/a&gt; helpers and a URL helper to name a few&lt;/li&gt;

&lt;li&gt;Utils.Web.MVC - common MVC specific classes and utils. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Please note that the source for the utils in this post has changed alot since the original blog posts, and someday I will write some more blog posts on the more interesting and useful classes inside.&lt;/p&gt;

&lt;p&gt;Firstly, lets start with the easy one : &lt;b&gt;gzip and cache the page response&lt;/b&gt;. I found some really good code at &lt;a href="/rashid/archive/2008/03/28/asp-net-mvc-action-filter-caching-and-compression.aspx" target="_blank" mce_href="/rashid/archive/2008/03/28/asp-net-mvc-action-filter-caching-and-compression.aspx"&gt;Kazi Manzur Rashid's blog&lt;/a&gt;. In his post he gives the solution to both caching and compressing the page response, by utilising 2 action flters. Just change the home controller in our project to the following : &lt;/p&gt;


&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Linq;&lt;br&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web;&lt;br&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web.Mvc;&lt;br&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; Utils.Web.MVC.Filters;&lt;br&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; MvcApplication2.Controllers&lt;br&gt;{&lt;br&gt;    [HandleError]&lt;br&gt;&lt;span style="font-weight: bold;"&gt;    [CacheFilter]&lt;/span&gt;&lt;br style="font-weight: bold;"&gt;&lt;span style="font-weight: bold;"&gt;    [CompressFilter]&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; HomeController : Controller&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult Index()&lt;br&gt;        {&lt;br&gt;            ViewData[&lt;span class="str"&gt;"Message"&lt;/span&gt;] = &lt;span class="str"&gt;"Welcome to ASP.NET MVC!"&lt;/span&gt;;&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;br&gt;        }&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; ActionResult About()&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; View();&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;&lt;/pre&gt;

&lt;p&gt;Our YSLOW score is now 75 and our total download size is 1K less. So we are getting there, but slowly...&lt;/p&gt;

&lt;p&gt;Next, we need to do something about the CSS. We are now going to &lt;b&gt;combine, gzip and cache the stylesheets&lt;/b&gt;. Follow these steps:&lt;br&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Add a namespace reference in the web.config : 
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;namespace&lt;/span&gt;&lt;span class="kwrd"&gt;="Utils.Web.MVC"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;Add a httphandler to the web.config : 
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;verb&lt;/span&gt;&lt;span class="kwrd"&gt;="*"&lt;/span&gt; &lt;span class="attr"&gt;path&lt;/span&gt;&lt;span class="kwrd"&gt;="css.axd"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="Utils.Web.HttpHandlers.CSSHandler, Utils.Web"&lt;/span&gt; &lt;span class="attr"&gt;validate&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;Change the site.master. Cut out the old references to the stylesheets and replace with this in the head:&lt;br&gt;
&lt;pre class="csharpcode"&gt;    &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; Html.CSS().Add(&lt;span class="str"&gt;"~/Content/Site.css"&lt;/span&gt;); &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; Html.CSS().Add(&lt;span class="str"&gt;"~/Content/Layout.css"&lt;/span&gt;); &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= Html.CSS().HTML &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Cool. With a few changes to the HTML, we get the same response but with a few improvements:&lt;br&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Our YSLOW score has jumped up to 83!&lt;/li&gt;

&lt;li&gt;We now have less requests (5) and our total file size is down to 130KB.&lt;/li&gt;
&lt;/ol&gt;
Finally, lets do something about the scripts. We are going to &lt;b&gt;combine, gzip and cache the script files&lt;/b&gt;. Follow these steps:&lt;br&gt;
&lt;ol&gt;
&lt;li&gt;Add the httphandler to the web.config : 
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;add&lt;/span&gt; &lt;span class="attr"&gt;verb&lt;/span&gt;&lt;span class="kwrd"&gt;="*"&lt;/span&gt; &lt;span class="attr"&gt;path&lt;/span&gt;&lt;span class="kwrd"&gt;="js.axd"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="Utils.Web.HttpHandlers.JSHandler, Utils.Web"&lt;/span&gt; &lt;span class="attr"&gt;validate&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/li&gt;

&lt;li&gt;Change the site.master. Cut out the old script references from the head and at the &lt;a href="http://developer.yahoo.com/performance/rules.html#js_bottom" target="_blank" mce_href="http://developer.yahoo.com/performance/rules.html#js_bottom"&gt;bottom of the file just before the closing of the body tag&lt;/a&gt;, add the following code:&lt;br&gt;
&lt;pre class="csharpcode"&gt;    &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; Html.Scripts().Add(&lt;span class="str"&gt;"~/Scripts/jquery-1.3.2.js"&lt;/span&gt;); &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; Html.Scripts().Add(&lt;span class="str"&gt;"~/Scripts/jquery.utils.js"&lt;/span&gt;); &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt; Html.Scripts().Add(&lt;span class="str"&gt;"~/Scripts/jqDnR.js"&lt;/span&gt;); &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="asp"&gt;&amp;lt;%&lt;/span&gt;= Html.Scripts().HTML &lt;span class="asp"&gt;%&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&amp;nbsp;Now what has changed? Well some major changes have occurred in the HTML output which has resulted in the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Our YSLOW score is a whopping 98!!! WOW!! Thats more like it. The only thing we are not getting an A score for is the Content Delivery Network section.&lt;/li&gt;

&lt;li&gt;But more importantly, our number of requests has dropped to 3 and the total size is only 27KB!&lt;/li&gt;

&lt;li&gt;Our total transfer time is now only 2.08 seconds!&lt;/li&gt;
&lt;/ol&gt;


&lt;p&gt;The HTML output is now the following: &lt;br&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;PUBLIC&lt;/span&gt; &lt;span class="kwrd"&gt;"-//W3C//DTD XHTML 1.0 Strict//EN"&lt;/span&gt; &lt;span class="kwrd"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;br&gt;    Home Page&lt;br&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;link&lt;/span&gt; &lt;span class="attr"&gt;rel&lt;/span&gt;&lt;span class="kwrd"&gt;="stylesheet"&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/css"&lt;/span&gt; &lt;span class="attr"&gt;href&lt;/span&gt;&lt;span class="kwrd"&gt;="/css.axd?f=%2fContent%2fSite.css%3fm%3d1%2c%2fContent%2fLayout.css%3fm%3d1&amp;amp;d=365"&lt;/span&gt; &lt;span class="attr"&gt;media&lt;/span&gt;&lt;span class="kwrd"&gt;="screen"&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;class&lt;/span&gt;&lt;span class="kwrd"&gt;="page"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;      &lt;span class="rem"&gt;&amp;lt;!-- extracted for example --&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;="/js.axd?f=%2fScripts%2fjquery-1.3.2.js%3fm%3d1%2c%2fScripts%2fjquery.utils.js%3fm%3d1%2c%2fScripts%2fjqDnR.js%3fm%3d1&amp;amp;d=365"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;The resulting firebug Net screenshot is:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/firebug2.gif"&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/firebug2.gif" border="0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And here is the YSlow screenshot:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/yslow3.gif"&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/yslow3.gif" border="0"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Conclusion:&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;With very few (and simple) changes there has been a massive improvement:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;b&gt;6&lt;/b&gt; requests down to &lt;b&gt;3&lt;/b&gt;&lt;/li&gt;

&lt;li&gt;&lt;b&gt;135K&lt;/b&gt; size down to &lt;b&gt;27K&lt;/b&gt;&lt;/li&gt;

&lt;li&gt;YSlow score from &lt;b&gt;73&lt;/b&gt; up to &lt;b&gt;98&lt;/b&gt;&lt;/li&gt;

&lt;li&gt;Download time from &lt;b&gt;4.11s&lt;/b&gt; down to &lt;b&gt;2.08s&lt;/b&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I also feel the changes have not been too hard to make and they still leave the view code in a very readable state (this is important in MVC). In my follow-on posts I want to go through the CSS and JS handlers that combine,gzip and cache the files. I will go through how your views and even your partial views can 'tell' the page what scripts or css to include and combine, and eliminate duplicates if necessary. &lt;b&gt;No longer does the master page have to know about all the scripts that will be used within the whole site up front.&lt;/b&gt;
&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Code/MVCSquash1.zip"&gt;Download the source&lt;/a&gt;. (Check out the Test.aspx view and PartialTest.ascx partial view to see a more realistic example)&lt;/p&gt;
</description><pubDate>Sun, 12 Apr 2009 20:30:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/squashing-the-asp-net-mvc-response-part-1</guid><category>.NET</category><category>ASP.NET</category><category>ASP.NET MVC</category><category>C#</category><category>MVC</category></item><item><title>LINQ Cheat Sheet</title><link>https://weblogs.asp.net:443/bradvincent/linq-cheat-sheet</link><description>&lt;p&gt;&amp;nbsp;A while ago when I was learning LINQ I searched the web for a 'cheat sheet'. I needed a single document that covered most of the common scenarios w.r.t LINQ so that I would not need to google every time I was writing LINQ queries. I found one very good one : &lt;a href="http://aspnetresources.com/blog/linq_sqo__cheat_sheet.aspx" target="_blank" mce_href="http://aspnetresources.com/blog/linq_sqo__cheat_sheet.aspx"&gt;http://aspnetresources.com/blog/linq_sqo__cheat_sheet.aspx&lt;/a&gt; . But I wanted more (as usual) so I created my own. I was also new to lambda expressions and I wanted to learn the differences between syntax in a LINQ query written in 'query syntax' and 'lambda syntax' so I also included that as part of my cheat sheet. Every query is given in both syntaxes. Here is a screenshot:&lt;br&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/sslinq.jpg"&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/sslinq.jpg" border="0"&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/LINQ%2520CHEAT%2520SHEET.zip"&gt;Download the LINQ CHEAT SHEET&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Please let me know what you think. Did it help you? Where could it be improved? What would you add?&lt;/p&gt;&lt;p&gt;You can also &lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Code/LINQTests.zip" mce_href="https://aspblogs.blob.core.windows.net/media/bradvincent/Code/LINQTests.zip"&gt;download the code&lt;/a&gt; that I used when creating the document. It also includes basic testing to make sure the queries of both syntaxes returned the same results. Beware as it may contain some bugs ;) &lt;/p&gt;&lt;p&gt;&lt;b&gt;UPDATE (3 Nov 2008) :&amp;nbsp;&lt;/b&gt; I updated the cheat sheet document. Changes made:&lt;br&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;made the left and right margins smaller&lt;/li&gt;&lt;li&gt;adjusted column widths to be equal&lt;/li&gt;&lt;li&gt;added new example under 'Ordering' section (thanks to RichardD - see comments)&lt;/li&gt;&lt;li&gt;added new example under 'Element Operators' section and updated notes (thanks to RichardD - see comments)&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description><pubDate>Sat, 01 Nov 2008 12:43:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/linq-cheat-sheet</guid><category>.NET 3.5</category><category>C#</category><category>LINQ</category></item><item><title>C# 3.0 Code Snippets</title><link>https://weblogs.asp.net:443/bradvincent/c-3-0-code-snippets</link><description>&lt;p&gt;A friend of mine found an excellent resource that I just had to share. It contains code snippets of examples of all the new features within C# 3.0. They are all taken from the book '&lt;b&gt;C# 3.0 in a Nutshell&lt;/b&gt;'. It looks like an excellent book for anyone wanting to learn the new features.&lt;/p&gt;&lt;p&gt;link : &lt;a href="http://www.albahari.com/nutshell/code.aspx" target="_blank" mce_href="http://www.albahari.com/nutshell/code.aspx"&gt;http://www.albahari.com/nutshell/code.aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;An overview of what the book contains : &lt;br&gt;&lt;/p&gt;&lt;p&gt;&lt;img src="file:///C:/Users/brad/AppData/Local/Temp/moz-screenshot-1.jpg" alt=""&gt;&lt;img src="http://www.albahari.com/nutshell/overview.png" mce_src="http://www.albahari.com/nutshell/overview.png" width="731" height="604"&gt; &lt;br&gt;&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description><pubDate>Mon, 27 Oct 2008 19:28:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/c-3-0-code-snippets</guid><category>.NET 3.0</category><category>C#</category></item><item><title>Helper Class : QueryString Builder (chainable)</title><link>https://weblogs.asp.net:443/bradvincent/helper-class-querystring-builder-chainable</link><description>&lt;p&gt;If you are a web developer you would definately have worked with the querystring. Most of the time you are just getting values from the querystring or adding querystring values to url's, but in some cases the querystring can really become a hassle to work with. A simple example of this can be seen in the following scenario : &lt;/p&gt;

&lt;p&gt;I have a control that contains a list of data displayed in a table. The current URL has no querystring by default, and in that case the first item in the grid is selected. Each row in the table contains a link to the same page, but a querystring is used to determine the selected row. On the itemdatabound event of the repeater I was setting the URL of a hyperlink on each row. Now I know this is a really simple example and using the itemdatabound event is overkill, but it's only an example ;) Now when setting the URL, I have to worry about if the same querystring value already exists in the current URL and if so replace it, else add it. (I hope you see where I'm going here.)&lt;/p&gt;

&lt;p&gt;Introducing the &lt;b&gt;Querystring builder class.&lt;/b&gt; The class can be easily used to build up querystrings (from scratch, the existing URL or any string in fact). I also made it &lt;b&gt;chainable &lt;/b&gt;(like the stringbuilder class). You can also encrypt and decrypt the querystring with ease (it uses my &lt;a href="/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx" mce_href="/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx"&gt;Cryptography&lt;/a&gt; classes). Here are a few examples of it's use:&lt;/p&gt;

&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;//create a querystring from the current URL, add 'id','user' and 'sessionId' values and remove an 'action' value&lt;/span&gt;&lt;br&gt;&lt;span class="rem"&gt;//output : "?id=123&amp;amp;user=brad&amp;amp;sessionId=ABC"&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; strQuery = QueryString.Current.Add(&lt;span class="str"&gt;"id"&lt;/span&gt;, &lt;span class="str"&gt;"123"&lt;/span&gt;).Add(&lt;span class="str"&gt;"user"&lt;/span&gt;, &lt;span class="str"&gt;"brad"&lt;/span&gt;).Add(&lt;span class="str"&gt;"sessionId"&lt;/span&gt;, &lt;span class="str"&gt;"ABC"&lt;/span&gt;).Remove(&lt;span class="str"&gt;"action"&lt;/span&gt;).ToString();&lt;br&gt;&lt;br&gt;&lt;span class="rem"&gt;//take an existing string and replace the 'id' value if it exists (which it does)&lt;/span&gt;&lt;br&gt;&lt;span class="rem"&gt;//output : "?id=5678&amp;amp;user=tony"&lt;/span&gt;&lt;br&gt;strQuery = &lt;span class="kwrd"&gt;new&lt;/span&gt; QueryString(&lt;span class="str"&gt;"id=1234&amp;amp;user=tony"&lt;/span&gt;).Add(&lt;span class="str"&gt;"id"&lt;/span&gt;, &lt;span class="str"&gt;"5678"&lt;/span&gt;, &lt;span class="kwrd"&gt;true&lt;/span&gt;).ToString();&lt;br&gt;&lt;br&gt;&lt;span class="rem"&gt;//create a querystring from the current URL, add an 'id' value and encrypt the result&lt;/span&gt;&lt;br&gt;&lt;span class="rem"&gt;//output : "?DhSbRo10vxUjYC5ChMXO5Q%3d%3d=dkxaLXpSg6aeM71fhHJ4ZQ%3d%3d"&lt;/span&gt;&lt;br&gt;strQuery = QueryString.Current.Add(&lt;span class="str"&gt;"id"&lt;/span&gt;, &lt;span class="str"&gt;"123"&lt;/span&gt;).Encrypt(&lt;span class="str"&gt;"my key"&lt;/span&gt;).ToString();&lt;br&gt;&lt;br&gt;&lt;span class="rem"&gt;//takes a previous querystring value, decrypts it using the same key and gets the 'id' value&lt;/span&gt;&lt;br&gt;&lt;span class="rem"&gt;//output : "123"&lt;/span&gt;&lt;br&gt;strQuery = &lt;span class="kwrd"&gt;new&lt;/span&gt; QueryString(strQuery).Decrypt(&lt;span class="str"&gt;"my key"&lt;/span&gt;)[&lt;span class="str"&gt;"id"&lt;/span&gt;];&lt;/pre&gt;
&lt;p&gt;Now obviously you cannot edit the current querystring, but the class is useful when manipulating the current querystring for other links or URL's. Here is the full code : 
&lt;/p&gt;
&lt;!-- code formatted by http://manoli.net/csharpformat/ --&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System;&lt;br&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Generic;&lt;br&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Text;&lt;br&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Web;&lt;br&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; System.Collections.Specialized;&lt;br&gt;&lt;br&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Utils.Web&lt;br&gt;{&lt;br&gt;    &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="rem"&gt;/// A chainable query string helper class.&lt;/span&gt;&lt;br&gt;    &lt;span class="rem"&gt;/// Example usage :&lt;/span&gt;&lt;br&gt;    &lt;span class="rem"&gt;/// string strQuery = QueryString.Current.Add("id", "179").ToString();&lt;/span&gt;&lt;br&gt;    &lt;span class="rem"&gt;/// string strQuery = new QueryString().Add("id", "179").ToString();&lt;/span&gt;&lt;br&gt;    &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; QueryString : NameValueCollection&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; QueryString() { }&lt;br&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; QueryString(&lt;span class="kwrd"&gt;string&lt;/span&gt; queryString) &lt;br&gt;        {&lt;br&gt;            FillFromString(queryString);&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; QueryString Current&lt;br&gt;        {&lt;br&gt;            get&lt;br&gt;            {&lt;br&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; QueryString().FromCurrent();&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// extracts a querystring from a full URL&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;param name="s"&amp;gt;the string to extract the querystring from&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;a string representing only the querystring&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ExtractQuerystring(&lt;span class="kwrd"&gt;string&lt;/span&gt; s)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(s))&lt;br&gt;            {&lt;br&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (s.Contains(&lt;span class="str"&gt;"?"&lt;/span&gt;))&lt;br&gt;                    &lt;span class="kwrd"&gt;return&lt;/span&gt; s.Substring(s.IndexOf(&lt;span class="str"&gt;"?"&lt;/span&gt;) + 1);&lt;br&gt;            }&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; s;&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// returns a querystring object based on a string&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;param name="s"&amp;gt;the string to parse&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;the QueryString object &amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; QueryString FillFromString(&lt;span class="kwrd"&gt;string&lt;/span&gt; s)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;base&lt;/span&gt;.Clear();&lt;br&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(s)) &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;;&lt;br&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; keyValuePair &lt;span class="kwrd"&gt;in&lt;/span&gt; ExtractQuerystring(s).Split(&lt;span class="str"&gt;'&amp;amp;'&lt;/span&gt;))&lt;br&gt;            {&lt;br&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(keyValuePair)) &lt;span class="kwrd"&gt;continue&lt;/span&gt;;&lt;br&gt;                &lt;span class="kwrd"&gt;string&lt;/span&gt;[] split = keyValuePair.Split(&lt;span class="str"&gt;'='&lt;/span&gt;);&lt;br&gt;                &lt;span class="kwrd"&gt;base&lt;/span&gt;.Add(split[0], &lt;br&gt;                    split.Length == 2 ? split[1] : &lt;span class="str"&gt;""&lt;/span&gt;);&lt;br&gt;            }&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;;&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// returns a QueryString object based on the current querystring of the request&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;the QueryString object &amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; QueryString FromCurrent()&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (HttpContext.Current != &lt;span class="kwrd"&gt;null&lt;/span&gt;)&lt;br&gt;            {&lt;br&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; FillFromString(HttpContext.Current.Request.QueryString.ToString());&lt;br&gt;            }&lt;br&gt;            &lt;span class="kwrd"&gt;base&lt;/span&gt;.Clear();&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;;&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// add a name value pair to the collection&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;param name="name"&amp;gt;the name&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;param name="value"&amp;gt;the value associated to the name&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;the QueryString object &amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; QueryString Add(&lt;span class="kwrd"&gt;string&lt;/span&gt; name, &lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; Add(name, &lt;span class="kwrd"&gt;value&lt;/span&gt;, &lt;span class="kwrd"&gt;false&lt;/span&gt;);&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// adds a name value pair to the collection&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;param name="name"&amp;gt;the name&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;param name="value"&amp;gt;the value associated to the name&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;param name="isUnique"&amp;gt;true if the name is unique within the querystring. This allows us to override existing values&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;the QueryString object &amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; QueryString Add(&lt;span class="kwrd"&gt;string&lt;/span&gt; name, &lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;value&lt;/span&gt;, &lt;span class="kwrd"&gt;bool&lt;/span&gt; isUnique)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; existingValue = &lt;span class="kwrd"&gt;base&lt;/span&gt;[name];&lt;br&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(existingValue))&lt;br&gt;                &lt;span class="kwrd"&gt;base&lt;/span&gt;.Add(name, HttpUtility.UrlEncodeUnicode(&lt;span class="kwrd"&gt;value&lt;/span&gt;));&lt;br&gt;            &lt;span class="kwrd"&gt;else&lt;/span&gt; &lt;span class="kwrd"&gt;if&lt;/span&gt; (isUnique)&lt;br&gt;                &lt;span class="kwrd"&gt;base&lt;/span&gt;[name] = HttpUtility.UrlEncodeUnicode(&lt;span class="kwrd"&gt;value&lt;/span&gt;);&lt;br&gt;            &lt;span class="kwrd"&gt;else&lt;/span&gt;&lt;br&gt;                &lt;span class="kwrd"&gt;base&lt;/span&gt;[name] += &lt;span class="str"&gt;","&lt;/span&gt; + HttpUtility.UrlEncodeUnicode(&lt;span class="kwrd"&gt;value&lt;/span&gt;);&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;;&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// removes a name value pair from the querystring collection&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;param name="name"&amp;gt;name of the querystring value to remove&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;the QueryString object&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; QueryString Remove(&lt;span class="kwrd"&gt;string&lt;/span&gt; name)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; existingValue = &lt;span class="kwrd"&gt;base&lt;/span&gt;[name];&lt;br&gt;            &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(existingValue))&lt;br&gt;                &lt;span class="kwrd"&gt;base&lt;/span&gt;.Remove(name);&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;;&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// clears the collection&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;the QueryString object &amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; QueryString Reset()&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;base&lt;/span&gt;.Clear();&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;;&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// Encrypts the keys and values of the entire querystring acc. to a key you specify&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;param name="key"&amp;gt;the key to use in the encryption&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;an encrypted querystring object&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; QueryString Encrypt(&lt;span class="kwrd"&gt;string&lt;/span&gt; key)&lt;br&gt;        {&lt;br&gt;            QueryString qs = &lt;span class="kwrd"&gt;new&lt;/span&gt; QueryString();&lt;br&gt;            Utils.Cryptography.Encryption enc = &lt;span class="kwrd"&gt;new&lt;/span&gt; Utils.Cryptography.Encryption();&lt;br&gt;            enc.Password = key;&lt;br&gt;            &lt;span class="kwrd"&gt;for&lt;/span&gt; (var i = 0; i &amp;lt; &lt;span class="kwrd"&gt;base&lt;/span&gt;.Keys.Count; i++)&lt;br&gt;            {&lt;br&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(&lt;span class="kwrd"&gt;base&lt;/span&gt;.Keys[i]))&lt;br&gt;                {&lt;br&gt;                    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; val &lt;span class="kwrd"&gt;in&lt;/span&gt; &lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="kwrd"&gt;base&lt;/span&gt;.Keys[i]].Split(&lt;span class="str"&gt;','&lt;/span&gt;))&lt;br&gt;                        qs.Add(enc.Encrypt(&lt;span class="kwrd"&gt;base&lt;/span&gt;.Keys[i]), enc.Encrypt(HttpUtility.UrlDecode(val)));&lt;br&gt;                }&lt;br&gt;            }&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; qs;&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// Decrypts the keys and values of the entire querystring acc. to a key you specify&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;param name="key"&amp;gt;the key to use in the decryption&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;a decrypted querystring object&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; QueryString Decrypt(&lt;span class="kwrd"&gt;string&lt;/span&gt; key)&lt;br&gt;        {&lt;br&gt;            QueryString qs = &lt;span class="kwrd"&gt;new&lt;/span&gt; QueryString();&lt;br&gt;            Utils.Cryptography.Encryption enc = &lt;span class="kwrd"&gt;new&lt;/span&gt; Utils.Cryptography.Encryption();&lt;br&gt;            enc.Password = key;&lt;br&gt;            &lt;span class="kwrd"&gt;for&lt;/span&gt; (var i = 0; i &amp;lt; &lt;span class="kwrd"&gt;base&lt;/span&gt;.Keys.Count; i++)&lt;br&gt;            {&lt;br&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(&lt;span class="kwrd"&gt;base&lt;/span&gt;.Keys[i]))&lt;br&gt;                {&lt;br&gt;                    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; val &lt;span class="kwrd"&gt;in&lt;/span&gt; &lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="kwrd"&gt;base&lt;/span&gt;.Keys[i]].Split(&lt;span class="str"&gt;','&lt;/span&gt;))&lt;br&gt;                        qs.Add(enc.Decrypt(HttpUtility.UrlDecode(&lt;span class="kwrd"&gt;base&lt;/span&gt;.Keys[i])), enc.Decrypt(HttpUtility.UrlDecode(val)));&lt;br&gt;                }&lt;br&gt;            }&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; qs;&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// overrides the default&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;param name="name"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;the associated decoded value for the specified name&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;[&lt;span class="kwrd"&gt;string&lt;/span&gt; name]&lt;br&gt;        {&lt;br&gt;            get&lt;br&gt;            {&lt;br&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; HttpUtility.UrlDecode(&lt;span class="kwrd"&gt;base&lt;/span&gt;[name]);&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// overrides the default indexer&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;param name="index"&amp;gt;&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;the associated decoded value for the specified index&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; &lt;span class="kwrd"&gt;this&lt;/span&gt;[&lt;span class="kwrd"&gt;int&lt;/span&gt; index]&lt;br&gt;        {&lt;br&gt;            get&lt;br&gt;            {&lt;br&gt;                &lt;span class="kwrd"&gt;return&lt;/span&gt; HttpUtility.UrlDecode(&lt;span class="kwrd"&gt;base&lt;/span&gt;[index]);&lt;br&gt;            }&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// checks if a name already exists within the query string collection&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;param name="name"&amp;gt;the name to check&amp;lt;/param&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;a boolean if the name exists&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;bool&lt;/span&gt; Contains(&lt;span class="kwrd"&gt;string&lt;/span&gt; name)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; existingValue = &lt;span class="kwrd"&gt;base&lt;/span&gt;[name];&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; !&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(existingValue);&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// outputs the querystring object to a string&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="rem"&gt;/// &amp;lt;returns&amp;gt;the encoded querystring as it would appear in a browser&amp;lt;/returns&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;override&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ToString()&lt;br&gt;        {&lt;br&gt;            StringBuilder builder = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder();&lt;br&gt;            &lt;span class="kwrd"&gt;for&lt;/span&gt; (var i = 0; i &amp;lt; &lt;span class="kwrd"&gt;base&lt;/span&gt;.Keys.Count; i++) &lt;br&gt;            {&lt;br&gt;                &lt;span class="kwrd"&gt;if&lt;/span&gt; (!&lt;span class="kwrd"&gt;string&lt;/span&gt;.IsNullOrEmpty(&lt;span class="kwrd"&gt;base&lt;/span&gt;.Keys[i]))&lt;br&gt;                {&lt;br&gt;                    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;string&lt;/span&gt; val &lt;span class="kwrd"&gt;in&lt;/span&gt; &lt;span class="kwrd"&gt;base&lt;/span&gt;[&lt;span class="kwrd"&gt;base&lt;/span&gt;.Keys[i]].Split(&lt;span class="str"&gt;','&lt;/span&gt;))&lt;br&gt;                        builder.Append((builder.Length == 0) ? &lt;span class="str"&gt;"?"&lt;/span&gt; : &lt;span class="str"&gt;"&amp;amp;"&lt;/span&gt;).Append(HttpUtility.UrlEncodeUnicode(&lt;span class="kwrd"&gt;base&lt;/span&gt;.Keys[i])).Append(&lt;span class="str"&gt;"="&lt;/span&gt;).Append(val);&lt;br&gt;                }&lt;br&gt;            }&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; builder.ToString();&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;&lt;/pre&gt;</description><pubDate>Mon, 27 Oct 2008 18:29:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/helper-class-querystring-builder-chainable</guid><category>.NET 3.5</category><category>ASP.NET</category><category>C#</category></item><item><title>(Better) JQuery IntelliSense in VS2008</title><link>https://weblogs.asp.net:443/bradvincent/better-jquery-intellisense-in-vs2008</link><description>&lt;p&gt;&lt;b&gt;UPDATE : &lt;/b&gt;&lt;a href="http://blogs.ipona.com/james/Default.aspx" target="_blank" mce_href="http://blogs.ipona.com/james/Default.aspx"&gt;James Hart&lt;/a&gt; has an excellent post about jQuery 1.3 intellisense - you &lt;b&gt;must&lt;/b&gt; &lt;a href="http://blogs.ipona.com/james/archive/2009/01/14/jquery-1.3-and-visual-studio-2008-intellisense.aspx" target="_blank" mce_href="http://blogs.ipona.com/james/archive/2009/01/14/jquery-1.3-and-visual-studio-2008-intellisense.aspx"&gt;check it out&lt;/a&gt;!&lt;br&gt;&lt;/p&gt;&lt;p&gt;I know, I know, this has been done before. The reason I'm writing this post, however, is to improve on what I have found on the web. For anyone wondering what jQuery is, goto the &lt;a href="http://jquery.com/" title="jQuery Home" target="_blank" mce_href="http://jquery.com/"&gt;jQuery&lt;/a&gt; site and also read this &lt;a href="http://docs.jquery.com/Tutorials:How_jQuery_Works" title="How jQuery Works" target="_blank" mce_href="http://docs.jquery.com/Tutorials:How_jQuery_Works"&gt;tutorial&lt;/a&gt;. Now onto the good stuff....&lt;/p&gt;

&lt;p&gt;If you are like me and you've read the many articles about how to get other javascript libraries to work in VS2008, you'll know that all you really need to do is install the visual studio &lt;a href="http://131.107.112.14/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=10826" title="VS2008 hotfix" target="_blank" mce_href="http://131.107.112.14/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=10826"&gt;HOTFIX&lt;/a&gt;. This patches your VS and among other things, gets the javascript intellisense working nicely.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Before the hotfix:&lt;/b&gt;&lt;br&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/no_intellisense.gif" border="1"&gt;&lt;br&gt;&lt;br&gt;&lt;b&gt;After the hotfix:&lt;/b&gt;&lt;br&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/with_intellisense1.gif" border="1"&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;You'll notice you can now use the jQuery $ shortcut function. &lt;/p&gt;

&lt;p&gt;At this point I was delighted. and then I typed &lt;b&gt;$(document).&lt;/b&gt; and I got no more intellisense, why???!!! After looking around some more, I found an article on the topic written by Rick Strahl : &lt;a href="http://www.west-wind.com/WebLog/posts/251271.aspx" target="_blank" mce_href="http://www.west-wind.com/WebLog/posts/251271.aspx"&gt;http://www.west-wind.com/WebLog/posts/251271.aspx&lt;/a&gt;. It helped explain things quite a bit and I recommend you read it. Basically, if you use the 'new' keyword in declaring jQuery objects, you get intellisense, so the following works nicely and you get intellisense:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;var doc = &lt;span class="kwrd"&gt;new&lt;/span&gt; jQuery(document);&lt;br&gt;doc.ready(function() {&lt;br&gt;    var div = &lt;span class="kwrd"&gt;new&lt;/span&gt; jQuery(&lt;span class="str"&gt;"#someDiv"&lt;/span&gt;);&lt;br&gt;    div.html(&lt;span class="str"&gt;"some text here!"&lt;/span&gt;);&lt;br&gt;    div.fadeOut(5000);&lt;br&gt;});&lt;/pre&gt;
&lt;p&gt;But I still wasn't satisfied. Why should I change the way I write my jQuery just so VS understands it? Yes I get intellisense, but I'm writing more code, and it's unnecessary code at that. Remember : jQuery is the "&lt;i&gt;write less, do more, JavaScript library&lt;/i&gt;".&lt;/p&gt;

&lt;p&gt;Then onto another point: what about one of the most powerful aspects of the jQuery architecture - the &lt;a href="http://docs.jquery.com/Tutorials:How_jQuery_Works#Chainability_.28The_Magic_of_jQuery.29" title="jQuery Chainability" target="_blank" mce_href="http://docs.jquery.com/Tutorials:How_jQuery_Works#Chainability_.28The_Magic_of_jQuery.29"&gt;chainability&lt;/a&gt;? The following code&lt;br&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;$(&lt;span class="str"&gt;"a"&lt;/span&gt;).addClass(&lt;span class="str"&gt;"test"&lt;/span&gt;).show().html(&lt;span class="str"&gt;"foo"&lt;/span&gt;);&lt;/pre&gt;
doesnt give you any intellisense whatsoever. In order to get intellisense, it has to be written as follows:&lt;br&gt;
&lt;pre class="csharpcode"&gt;var a = &lt;span class="kwrd"&gt;new&lt;/span&gt; jQuery(&lt;span class="str"&gt;"a"&lt;/span&gt;);&lt;br&gt;a.addClass(&lt;span class="str"&gt;"test"&lt;/span&gt;);&lt;br&gt;a.show();&lt;br&gt;a.html(&lt;span class="str"&gt;"foo"&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;
So intellisense for jQuery at this point is actually quite useless I thought. Because in order to use it, we have to write double the amount of code, and jQuery's chainability power isnt being utilised at all. :( &lt;br&gt;Another bummer was the fact that the method info for the jQuery functions was seriously lacking. Obviously this is because the jQuery library has been written to be as small as possible. But it would be nice if the functions were explained together with the paramaters (exactly like we are used to when writing c# code).&lt;br&gt;&lt;/p&gt;

&lt;p&gt;so back to google and back to searching for alternatives...&lt;br&gt;This is when I found this gem of an article written by James Hart : &lt;a href="http://blogs.ipona.com/james/archive/2008/02/15/JQuery-IntelliSense-in-Visual-Studio-2008.aspx" target="_blank" mce_href="http://blogs.ipona.com/james/archive/2008/02/15/JQuery-IntelliSense-in-Visual-Studio-2008.aspx"&gt;http://blogs.ipona.com/james/archive/2008/02/15/JQuery-IntelliSense-in-Visual-Studio-2008.aspx&lt;/a&gt; .&amp;nbsp; And it literally solved all my problems. Here is what the method info was before:&lt;br&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/no_intellisense_method_info.gif" border="1"&gt;&lt;br&gt;And this is how it looks afterwards:&lt;br&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/with_intellisense_method_info.gif" border="1"&gt;&lt;br&gt;Big improvement! And here is the intellisense in action (using chainability):&lt;br&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/with_intellisense_chainability.gif" border="1"&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Awesome!!!!&lt;/b&gt; But how does it work? Basically, a new javascript is generated and referenced from the page. This new file is just a list of methods with no functionality and it 'tricks' VS into producing nice intellisense. It also uses XML documentation to provide useful parameter listings and return types. (You can read more about javascript documentation comments here: &lt;a href="/bleroy/archive/2007/04/23/the-format-for-javascript-doc-comments.aspx" target="_blank" mce_href="/bleroy/archive/2007/04/23/the-format-for-javascript-doc-comments.aspx"&gt;http://weblogs.asp.net/bleroy/archive/2007/04/23/the-format-for-javascript-doc-comments.aspx&lt;/a&gt; ). For ASPX pages, all you need to do is include the script inside an invisible placeholder :
&lt;br&gt;
&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&amp;lt;script type=&lt;span class="str"&gt;"text/javascript"&lt;/span&gt; src=&lt;span class="str"&gt;"jQuery.js"&lt;/span&gt; &amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;&amp;lt;asp:PlaceHolder runat=&lt;span class="str"&gt;"server"&lt;/span&gt; visible=&lt;span class="str"&gt;"false"&lt;/span&gt;&amp;gt;&lt;br&gt;    &amp;lt;script type=&lt;span class="str"&gt;"text/javascript"&lt;/span&gt; src=&lt;span class="str"&gt;"JQuery.Intellisense.js"&lt;/span&gt; &amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;&amp;lt;/asp:PlaceHolder&amp;gt;&lt;/pre&gt;This is to stop the file from actually being included in the rendered page. Note that it must also be after the reference to the 'real' jQuery file. &lt;br&gt;And in other external .JS files that use jQuery code, add the following to the top of the file:&lt;br&gt;
&lt;pre class="csharpcode"&gt;/// &amp;lt;reference path=&lt;span class="str"&gt;"jquery.intellisense.js"&lt;/span&gt;/&amp;gt;&lt;/pre&gt;

&lt;p&gt;So now I can write my jQuery code as I did before and I have excellent method information and intellisense. This works fine in external javascript files, plain ASPX pages, master pages, content pages and user controls.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;So are there still some issues?&lt;/b&gt; &lt;b&gt;Yes there are.&lt;/b&gt; Firstly the generated file is using an outdated jQuery version 1.2.1 and even more outdated jQuery documentation version 1.1.2. This is by no means the fault of the author, but rather the jQuery team who have not updated the XML documentation. Secondly, certain functions in jQuery have optional parameters and return different types based on those parameters e.g. the html() function. These functions unfortunately don't give me intellisense because the generator gives them a return type of "Object" in the XML comments. No problem, just edit the generated file and change it where it has &lt;i&gt;&amp;lt;returns type="&lt;b&gt;Object&lt;/b&gt;"&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt; to &lt;i&gt;&amp;lt;returns type="&lt;b&gt;jQuery&lt;/b&gt;"&amp;gt;&amp;lt;/returns&amp;gt;&lt;/i&gt;&lt;br&gt;A list of the functions I found that need changing are :&lt;br&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;css&lt;/li&gt;

&lt;li&gt;html&lt;/li&gt;

&lt;li&gt;attr&lt;/li&gt;

&lt;li&gt;text&lt;/li&gt;

&lt;li&gt;val&lt;/li&gt;

&lt;li&gt;height&lt;/li&gt;

&lt;li&gt;width&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ok, so stricly speaking, it's not correct, because these functions will return a non jQuery object when nothing is passed in, but &lt;b&gt;what the hell&lt;/b&gt;. I still get more intellisense than before. And besides, you must at least have some idea of what the functions do, and not rely on intellisense exclusively to write code ;)&lt;br&gt;&lt;/p&gt;

&lt;p&gt;You can download my &lt;a href="http://weblogs.asp.net/blogs/bradvincent/JQuery.Intellisense.zip"&gt;JQuery.Intellisense&lt;/a&gt; file with the changes already made. It is using API version: 1.2.3 and Documentation version: 1.2.2.&lt;/p&gt;

&lt;p&gt;&lt;b&gt;jQuery Intellisense In 3 Easy Steps&lt;/b&gt;&lt;br&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install VS2008 &lt;a href="http://131.107.112.14/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=10826" target="_blank" mce_href="http://131.107.112.14/VisualStudio/Downloads/DownloadDetails.aspx?DownloadID=10826"&gt;hotfix &lt;/a&gt;&lt;/li&gt;

&lt;li&gt;Generate a JQuery.Intellisense.js stub file. Either goto &lt;a href="http://www.infobasis.com/sandpit/jQuery-Intellisense/" target="_blank" mce_href="http://www.infobasis.com/sandpit/jQuery-Intellisense/"&gt;http://www.infobasis.com/sandpit/jQuery-Intellisense/&lt;/a&gt; and generate it, or download a more up to date one (including minor fixes) from &lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/JQuery.Intellisense.zip"&gt;here&lt;/a&gt;. save it to the same folder as your jQuery file&lt;/li&gt;

&lt;li&gt;Add a invisible placeholder into your header and reference the new .js file:&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;asp:PlaceHolder runat="server" visible="false"&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;script type="text/javascript" src="JQuery.Intellisense.js" &amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;/asp:PlaceHolder&amp;gt;&lt;br&gt;or add a referenece at the top of your .js file&lt;br&gt;/// &amp;lt;reference path=&lt;span class="str"&gt;"jquery.intellisense.js"&lt;/span&gt;/&amp;gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;b&gt;Download &lt;/b&gt;the whole website: &lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/JqueryIntellisenseWebsite.zip"&gt;JqueryIntellisenseWebsite.zip&lt;/a&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Code samples&lt;/b&gt;:&lt;br&gt;&lt;/p&gt;

&lt;p&gt;simple jQuery page with full intellisense:&lt;br&gt;&lt;br&gt;
&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;PUBLIC&lt;/span&gt; &lt;span class="kwrd"&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/span&gt; &lt;span class="kwrd"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;I have intellisense!&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;="jQuery.js"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &amp;lt;asp:PlaceHolder runat=&lt;span class="str"&gt;"server"&lt;/span&gt; visible=&lt;span class="str"&gt;"false"&lt;/span&gt;&amp;gt;&lt;br&gt;        &amp;lt;script type=&lt;span class="str"&gt;"text/javascript"&lt;/span&gt; src=&lt;span class="str"&gt;"JQuery.Intellisense.js"&lt;/span&gt; &amp;gt;&amp;lt;/script&amp;gt;&lt;br&gt;    &amp;lt;/asp:PlaceHolder&amp;gt;&lt;br&gt;&lt;br&gt;    &amp;lt;script type=&lt;span class="str"&gt;"text/javascript"&lt;/span&gt;&amp;gt;&lt;br&gt;        $(&lt;span class="kwrd"&gt;function&lt;/span&gt;() {&lt;br&gt;            $(&lt;span class="str"&gt;"#someDiv"&lt;/span&gt;).hide().html(&lt;span class="str"&gt;"Some text here!!!"&lt;/span&gt;).addClass(&lt;span class="str"&gt;"bold"&lt;/span&gt;).fadeIn(1000).fadeOut(2000);&lt;br&gt;        });&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;style&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/css"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    .bold{ font-weight:bold; }&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;style&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="form1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="someDiv"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;&lt;br&gt;simple master page :&lt;br&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Master Language="C#" AutoEventWireup="true" CodeFile="MasterPage.master.cs" Inherits="MasterPage" %&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;!&lt;/span&gt;&lt;span class="html"&gt;DOCTYPE&lt;/span&gt; &lt;span class="attr"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;PUBLIC&lt;/span&gt; &lt;span class="kwrd"&gt;"-//W3C//DTD XHTML 1.0 Transitional//EN"&lt;/span&gt; &lt;span class="kwrd"&gt;"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt; &lt;span class="attr"&gt;xmlns&lt;/span&gt;&lt;span class="kwrd"&gt;="http://www.w3.org/1999/xhtml"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;Untitled Page&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;title&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;="jQuery.js"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &amp;lt;asp:PlaceHolder runat=&lt;span class="str"&gt;"server"&lt;/span&gt; visible=&lt;span class="str"&gt;"false"&lt;/span&gt;&amp;gt;&lt;br&gt;        &amp;lt;script type=&lt;span class="str"&gt;"text/javascript"&lt;/span&gt; src=&lt;span class="str"&gt;"JQuery.Intellisense.js"&lt;/span&gt; &amp;gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:PlaceHolder&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;    &lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:ContentPlaceHolder&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="head"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:ContentPlaceHolder&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;head&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="form1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:ContentPlaceHolder&lt;/span&gt; &lt;span class="attr"&gt;id&lt;/span&gt;&lt;span class="kwrd"&gt;="ContentPlaceHolder1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:ContentPlaceHolder&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;div&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;form&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;body&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;html&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;
&lt;br&gt;
simple content page :&lt;br&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" Title="Untitled &lt;br&gt;&lt;br&gt;Page" %&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Content&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="Content1"&lt;/span&gt; &lt;span class="attr"&gt;ContentPlaceHolderID&lt;/span&gt;&lt;span class="kwrd"&gt;="head"&lt;/span&gt; &lt;span class="attr"&gt;Runat&lt;/span&gt;&lt;span class="kwrd"&gt;="Server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        $(&lt;span class="kwrd"&gt;function&lt;/span&gt;() {&lt;br&gt;            $(&lt;span class="str"&gt;"#someDiv"&lt;/span&gt;).addClass(&lt;span class="str"&gt;"bold"&lt;/span&gt;).fadeIn(2000).fadeOut(1000).html(&lt;span class="str"&gt;"gone"&lt;/span&gt;);&lt;br&gt;        });&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:Content&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Content&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="Content2"&lt;/span&gt; &lt;span class="attr"&gt;ContentPlaceHolderID&lt;/span&gt;&lt;span class="kwrd"&gt;="ContentPlaceHolder1"&lt;/span&gt; &lt;span class="attr"&gt;Runat&lt;/span&gt;&lt;span class="kwrd"&gt;="Server"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:Content&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;&lt;br&gt;
simple user control :&lt;br&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="asp"&gt;&amp;lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="TestControl.ascx.cs" Inherits="TestControl" %&amp;gt;&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:PlaceHolder&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="PlaceHolder1"&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;="server"&lt;/span&gt; &lt;span class="attr"&gt;visible&lt;/span&gt;&lt;span class="kwrd"&gt;="false"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt; &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;="text/javascript"&lt;/span&gt; &lt;span class="attr"&gt;src&lt;/span&gt;&lt;span class="kwrd"&gt;="JQuery.Intellisense.js"&lt;/span&gt; &lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;br&gt;    &amp;lt;/asp:PlaceHolder&amp;gt;&lt;br&gt;    &amp;lt;script type=&lt;span class="str"&gt;"text/javascript"&lt;/span&gt;&amp;gt;&lt;br&gt;        $(&lt;span class="kwrd"&gt;function&lt;/span&gt;() {&lt;br&gt;            $(&lt;span class="str"&gt;"#someDiv"&lt;/span&gt;).hide().html(&lt;span class="str"&gt;"Some text here!!!"&lt;/span&gt;).addClass(&lt;span class="str"&gt;"bold"&lt;/span&gt;).fadeIn(1000).fadeOut(2000);&lt;br&gt;        });&lt;br&gt;    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;script&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;</description><pubDate>Mon, 28 Apr 2008 17:02:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/better-jquery-intellisense-in-vs2008</guid><category>.NET</category><category>ASP.NET</category><category>jQuery</category><category>VS2008</category></item><item><title>Creating vCalendars programmatically in C#</title><link>https://weblogs.asp.net:443/bradvincent/creating-vcalendars-programmatically</link><description>&lt;p&gt;Have you ever wanted to send out meeting requests from your code? Well I wanted to do just that today. And I didnt want to reference the Outlook dll's. I simply wanted to send an email to an attendee's email address. &lt;/p&gt;&lt;p&gt;After much searching and alot of useless code I found a gem at &lt;a href="http://chuckdotnet.blogspot.com" target="_blank" mce_href="http://chuckdotnet.blogspot.com"&gt;http://chuckdotnet.blogspot.com&lt;/a&gt;. I took the code there and modified it slightly so that you can send the meeting request to multiple recipients (attendees) at once. &lt;/p&gt;&lt;p&gt;below is the method that creates the system.net.mailmessage object with all the necessary alternateviews, so that when opened in outlook it behaves exactly like a meeting request that was sent from within outlook. remember to add using System.Net.Mail;using System.Net.Mime; to the top of your code.&lt;/p&gt;
&lt;br&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; MailMessage CreateMeetingRequest(DateTime start, DateTime end, &lt;span class="kwrd"&gt;string&lt;/span&gt; subject, &lt;span class="kwrd"&gt;string&lt;/span&gt; summary,&lt;br&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; location, &lt;span class="kwrd"&gt;string&lt;/span&gt; organizerName, &lt;span class="kwrd"&gt;string&lt;/span&gt; organizerEmail, &lt;span class="kwrd"&gt;string&lt;/span&gt; attendeeName, &lt;span class="kwrd"&gt;string&lt;/span&gt; attendeeEmail)&lt;br&gt;{&lt;br&gt;    MailAddressCollection col = &lt;span class="kwrd"&gt;new&lt;/span&gt; MailAddressCollection();&lt;br&gt;    col.Add(&lt;span class="kwrd"&gt;new&lt;/span&gt; MailAddress(attendeeEmail, attendeeName));&lt;br&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; CreateMeetingRequest(start, end, subject, summary, location, organizerName, organizerEmail, col);&lt;br&gt;}&lt;br&gt;&lt;br&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; MailMessage CreateMeetingRequest(DateTime start, DateTime end, &lt;span class="kwrd"&gt;string&lt;/span&gt; subject, &lt;span class="kwrd"&gt;string&lt;/span&gt; summary,&lt;br&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; location, &lt;span class="kwrd"&gt;string&lt;/span&gt; organizerName, &lt;span class="kwrd"&gt;string&lt;/span&gt; organizerEmail, MailAddressCollection attendeeList)&lt;br&gt;{&lt;br&gt;    MailMessage msg = &lt;span class="kwrd"&gt;new&lt;/span&gt; MailMessage();&lt;br&gt;&lt;br&gt;    &lt;span class="rem"&gt;//  Set up the different mime types contained in the message&lt;/span&gt;&lt;br&gt;    System.Net.Mime.ContentType textType = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Net.Mime.ContentType(&lt;span class="str"&gt;"text/plain"&lt;/span&gt;);&lt;br&gt;    System.Net.Mime.ContentType HTMLType = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Net.Mime.ContentType(&lt;span class="str"&gt;"text/html"&lt;/span&gt;);&lt;br&gt;    System.Net.Mime.ContentType calendarType = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Net.Mime.ContentType(&lt;span class="str"&gt;"text/calendar"&lt;/span&gt;);&lt;br&gt;&lt;br&gt;    &lt;span class="rem"&gt;//  Add parameters to the calendar header&lt;/span&gt;&lt;br&gt;    calendarType.Parameters.Add(&lt;span class="str"&gt;"method"&lt;/span&gt;, &lt;span class="str"&gt;"REQUEST"&lt;/span&gt;);&lt;br&gt;    calendarType.Parameters.Add(&lt;span class="str"&gt;"name"&lt;/span&gt;, &lt;span class="str"&gt;"meeting.ics"&lt;/span&gt;);&lt;br&gt;&lt;br&gt;    &lt;span class="rem"&gt;//  Create message body parts&lt;/span&gt;&lt;br&gt;    &lt;span class="rem"&gt;//  create the Body in text format&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; bodyText = &lt;span class="str"&gt;"Type:Single Meeting\r\nOrganizer: {0}\r\nStart Time:{1}\r\nEnd Time:{2}\r\nTime Zone:{3}\r\nLocation: {4}\r\n\r\n*~*~*~*~*~*~*~*~*~*\r\n\r\n{5}"&lt;/span&gt;;&lt;br&gt;    bodyText = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(bodyText,&lt;br&gt;        organizerName,&lt;br&gt;        start.ToLongDateString() + &lt;span class="str"&gt;" "&lt;/span&gt; + start.ToLongTimeString(),&lt;br&gt;        end.ToLongDateString() + &lt;span class="str"&gt;" "&lt;/span&gt; + end.ToLongTimeString(),&lt;br&gt;        System.TimeZone.CurrentTimeZone.StandardName,&lt;br&gt;        location,&lt;br&gt;        summary);&lt;br&gt;&lt;br&gt;    AlternateView textView = AlternateView.CreateAlternateViewFromString(bodyText, textType);&lt;br&gt;    msg.AlternateViews.Add(textView);&lt;br&gt;&lt;br&gt;    &lt;span class="rem"&gt;//create the Body in HTML format&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; bodyHTML = &lt;span class="str"&gt;"&amp;lt;!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 3.2//EN\"&amp;gt;\r\n&amp;lt;HTML&amp;gt;\r\n&amp;lt;HEAD&amp;gt;\r\n&amp;lt;META HTTP-EQUIV=\"Content-Type\" CONTENT=\"text/html; charset=utf-8\"&amp;gt;\r\n&amp;lt;META NAME=\"Generator\" CONTENT=\"MS Exchange Server version 6.5.7652.24\"&amp;gt;\r\n&amp;lt;TITLE&amp;gt;{0}&amp;lt;/TITLE&amp;gt;\r\n&amp;lt;/HEAD&amp;gt;\r\n&amp;lt;BODY&amp;gt;\r\n&amp;lt;!-- Converted from text/plain format --&amp;gt;\r\n&amp;lt;P&amp;gt;&amp;lt;FONT SIZE=2&amp;gt;Type:Single Meeting&amp;lt;BR&amp;gt;\r\nOrganizer:{1}&amp;lt;BR&amp;gt;\r\nStart Time:{2}&amp;lt;BR&amp;gt;\r\nEnd Time:{3}&amp;lt;BR&amp;gt;\r\nTime Zone:{4}&amp;lt;BR&amp;gt;\r\nLocation:{5}&amp;lt;BR&amp;gt;\r\n&amp;lt;BR&amp;gt;\r\n*~*~*~*~*~*~*~*~*~*&amp;lt;BR&amp;gt;\r\n&amp;lt;BR&amp;gt;\r\n{6}&amp;lt;BR&amp;gt;\r\n&amp;lt;/FONT&amp;gt;\r\n&amp;lt;/P&amp;gt;\r\n\r\n&amp;lt;/BODY&amp;gt;\r\n&amp;lt;/HTML&amp;gt;"&lt;/span&gt;;&lt;br&gt;    bodyHTML = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(bodyHTML,&lt;br&gt;        summary,&lt;br&gt;        organizerName, &lt;br&gt;        start.ToLongDateString() + &lt;span class="str"&gt;" "&lt;/span&gt; + start.ToLongTimeString(),&lt;br&gt;        end.ToLongDateString() + &lt;span class="str"&gt;" "&lt;/span&gt; + end.ToLongTimeString(),&lt;br&gt;        System.TimeZone.CurrentTimeZone.StandardName,&lt;br&gt;        location,&lt;br&gt;        summary);&lt;br&gt;&lt;br&gt;    AlternateView HTMLView = AlternateView.CreateAlternateViewFromString(bodyHTML, HTMLType);&lt;br&gt;    msg.AlternateViews.Add(HTMLView);&lt;br&gt;&lt;br&gt;    &lt;span class="rem"&gt;//create the Body in VCALENDAR format&lt;/span&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; calDateFormat = &lt;span class="str"&gt;"yyyyMMddTHHmmssZ"&lt;/span&gt;;&lt;br&gt;    &lt;span class="kwrd"&gt;string&lt;/span&gt; bodyCalendar = &lt;span class="str"&gt;"BEGIN:VCALENDAR\r\nMETHOD:REQUEST\r\nPRODID:Microsoft CDO for Microsoft Exchange\r\nVERSION:2.0\r\nBEGIN:VTIMEZONE\r\nTZID:(GMT-06.00) Central Time (US &amp;amp; Canada)\r\nX-MICROSOFT-CDO-TZID:11\r\nBEGIN:STANDARD\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0500\r\nTZOFFSETTO:-0600\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=11;BYDAY=1SU\r\nEND:STANDARD\r\nBEGIN:DAYLIGHT\r\nDTSTART:16010101T020000\r\nTZOFFSETFROM:-0600\r\nTZOFFSETTO:-0500\r\nRRULE:FREQ=YEARLY;WKST=MO;INTERVAL=1;BYMONTH=3;BYDAY=2SU\r\nEND:DAYLIGHT\r\nEND:VTIMEZONE\r\nBEGIN:VEVENT\r\nDTSTAMP:{8}\r\nDTSTART:{0}\r\nSUMMARY:{7}\r\nUID:{5}\r\nATTENDEE;ROLE=REQ-PARTICIPANT;PARTSTAT=NEEDS-ACTION;RSVP=TRUE;CN=\"{9}\":MAILTO:{9}\r\nACTION;RSVP=TRUE;CN=\"{4}\":MAILTO:{4}\r\nORGANIZER;CN=\"{3}\":mailto:{4}\r\nLOCATION:{2}\r\nDTEND:{1}\r\nDESCRIPTION:{7}\\N\r\nSEQUENCE:1\r\nPRIORITY:5\r\nCLASS:\r\nCREATED:{8}\r\nLAST-MODIFIED:{8}\r\nSTATUS:CONFIRMED\r\nTRANSP:OPAQUE\r\nX-MICROSOFT-CDO-BUSYSTATUS:BUSY\r\nX-MICROSOFT-CDO-INSTTYPE:0\r\nX-MICROSOFT-CDO-INTENDEDSTATUS:BUSY\r\nX-MICROSOFT-CDO-ALLDAYEVENT:FALSE\r\nX-MICROSOFT-CDO-IMPORTANCE:1\r\nX-MICROSOFT-CDO-OWNERAPPTID:-1\r\nX-MICROSOFT-CDO-ATTENDEE-CRITICAL-CHANGE:{8}\r\nX-MICROSOFT-CDO-OWNER-CRITICAL-CHANGE:{8}\r\nBEGIN:VALARM\r\nACTION:DISPLAY\r\nDESCRIPTION:REMINDER\r\nTRIGGER;RELATED=START:-PT00H15M00S\r\nEND:VALARM\r\nEND:VEVENT\r\nEND:VCALENDAR\r\n"&lt;/span&gt;;&lt;br&gt;    bodyCalendar = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(bodyCalendar,&lt;br&gt;        start.ToUniversalTime().ToString(calDateFormat),&lt;br&gt;        end.ToUniversalTime().ToString(calDateFormat),&lt;br&gt;        location,&lt;br&gt;        organizerName,&lt;br&gt;        organizerEmail,&lt;br&gt;        Guid.NewGuid().ToString(&lt;span class="str"&gt;"B"&lt;/span&gt;),&lt;br&gt;        summary,&lt;br&gt;        subject,&lt;br&gt;        DateTime.Now.ToUniversalTime().ToString(calDateFormat),&lt;br&gt;        attendeeList.ToString());&lt;br&gt;&lt;br&gt;    AlternateView calendarView = AlternateView.CreateAlternateViewFromString(bodyCalendar, calendarType);&lt;br&gt;    calendarView.TransferEncoding = TransferEncoding.SevenBit;&lt;br&gt;    msg.AlternateViews.Add(calendarView);&lt;br&gt;&lt;br&gt;    &lt;span class="rem"&gt;//  Adress the message&lt;/span&gt;&lt;br&gt;    msg.From = &lt;span class="kwrd"&gt;new&lt;/span&gt; MailAddress(organizerEmail);&lt;br&gt;    &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (MailAddress attendee &lt;span class="kwrd"&gt;in&lt;/span&gt; attendeeList)&lt;br&gt;    {&lt;br&gt;        msg.To.Add(attendee);&lt;br&gt;    }&lt;br&gt;    msg.Subject = subject;&lt;br&gt;&lt;br&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; msg;&lt;br&gt;}&lt;/pre&gt;</description><pubDate>Wed, 16 Jan 2008 19:29:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/creating-vcalendars-programmatically</guid><category>C#</category><category>Free Code</category></item><item><title>UberUtils - Part 5 : Configuration</title><link>https://weblogs.asp.net:443/bradvincent/uberutils-part-5-configuration</link><description>&lt;p&gt;ÜberUtils Series posts so far :&lt;br&gt;
&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://weblogs.asp.net/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx" target="_blank" mce_href="http://weblogs.asp.net/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx"&gt;Part 1 : Cryptography&lt;/a&gt; - Hashing&lt;/li&gt;

&lt;li&gt;&lt;a href="http://weblogs.asp.net/bradvincent/archive/2007/10/07/220-berutils-part-1-cryptography-continued.aspx" target="_blank" mce_href="http://weblogs.asp.net/bradvincent/archive/2007/10/07/220-berutils-part-1-cryptography-continued.aspx"&gt;Part 2 : Cryptography (Continued)&lt;/a&gt; - Encryption &lt;br&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="http://weblogs.asp.net/bradvincent/archive/2007/10/22/220-berutils-part-3-strings.aspx" target="_blank" mce_href="http://weblogs.asp.net/bradvincent/archive/2007/10/22/220-berutils-part-3-strings.aspx"&gt;Part 3 : Strings&lt;/a&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="/bradvincent/archive/2007/12/13/220-berutils-part-4-collections.aspx" target="_blank" mce_href="/bradvincent/archive/2007/12/13/220-berutils-part-4-collections.aspx"&gt;Part 4 : Collections&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;**** Please note that this code is using .NET 3.5 ****&lt;br&gt;&lt;/p&gt;

&lt;p&gt;Now onto the post - everyone I'm sure has used the system.configuration namespace before in a project. If you haven't then shame on you. If you have, then you know it should be used for storing things like :&lt;br&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;admin email address&lt;/li&gt;

&lt;li&gt;connection strings to a database&lt;/li&gt;

&lt;li&gt;log file path&lt;/li&gt;

&lt;li&gt;Tax amounts&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and so on. I am a strong believer in NEVER hard code a setting. There is just no reason to do so. What happens if a setting changes down the line? Lets use a webmaster email as an example. You would have to locate wherever you use the email address (probably more than one place) and edit it. Then recompile and redeploy your changes. What a mission! Instead, just store it in the appsettings section of the .config file and edit the setting there whenever you need to. &lt;/p&gt;

&lt;p&gt;I really do like using the appsettings and connectionstring sections in the .config files, but I think there is room for improvement. Wouldn't it be nice if appsettings was strongly typed for types other than string? Indeed it would. Here's an example: you store a "Testing" appsetting that determines if your website is in testing mode. If it is in testing mode, then you send all emails to Admin instead of sending emails to the actual users. Now every time you want to check if the site is in testing mode you have to convert the appsetting to a boolean first. Similarly with a Tax appsetting. You have to convert it to decimal every time before you can use it.&lt;br&gt; &lt;/p&gt;

&lt;p&gt;This then follows directly onto my next question : Wouldn't it be nice if appsettings and connectionstrings had default values? Yes again. Let's say the "testing" appsetting we spoke about earlier wasn't in the .config file. We would then want it to default to true. Maybe our tax appsetting should default to 0.14 and maybe we always use the same default connectionstring in our data access layer. Defaults would be great.&lt;br&gt;&lt;/p&gt;

&lt;p&gt;I address these two shortfalls with &lt;b&gt;Utils.Configuration.&lt;/b&gt; Lets look at some examples:&lt;br&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; bTesting = Utils.Configuration.ConfigurationManager.AppSettings[&lt;span class="str"&gt;"Testing"&lt;/span&gt;, &lt;span class="kwrd"&gt;true&lt;/span&gt;];&lt;/pre&gt;this gets the testing appsetting with a deafult of true (if we forgot to add the appsetting into the .config file). Notice too how it's strongly typed to be boolean. You could've also done it this way :&lt;br&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;bool&lt;/span&gt; bTesting = Utils.Configuration.ConfigurationManager.AppSettings.GetValue(&lt;span class="str"&gt;"Testing"&lt;/span&gt;, &lt;span class="kwrd"&gt;true&lt;/span&gt;);&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;This goes the same for the other types : Decimals, Ints, Doubles, Datetimes and obviously strings.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;decimal&lt;/span&gt; nTax = Utils.Configuration.ConfigurationManager.AppSettings[&lt;span class="str"&gt;"Tax"&lt;/span&gt;, 0.14M];&lt;/pre&gt;The same applies for connectionstrings, except the output is obviously always a string. You can also check if a connection string exists so you can provide better error handling :&lt;br&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;if&lt;/span&gt; (ConfigurationManager.ConnectionStrings.Exists(&lt;span class="str"&gt;"TestConn2"&lt;/span&gt;))&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;return&lt;/span&gt; ConfigurationManager.ConnectionStrings[&lt;span class="str"&gt;"TestConn2"&lt;/span&gt;, &lt;span class="str"&gt;"Driver={SQL Server};Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;"&lt;/span&gt;];&lt;br&gt;}&lt;/pre&gt;
download the assembly with unit tests &lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Code/Utils_ver4.zip"&gt;here&lt;/a&gt;&lt;br&gt;</description><pubDate>Wed, 16 Jan 2008 17:07:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/uberutils-part-5-configuration</guid><category>.NET 3.5</category><category>C#</category><category>Free Code</category></item><item><title>UberUtils - Part 4 : Collections</title><link>https://weblogs.asp.net:443/bradvincent/220-berutils-part-4-collections</link><description>&lt;p&gt;&amp;nbsp;ÜberUtils Series posts so far :&lt;br&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="http://weblogs.asp.net/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx" target="_blank" mce_href="http://weblogs.asp.net/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx"&gt;Part 1 : Cryptography&lt;/a&gt; - Hashing&lt;/li&gt;

&lt;li&gt;&lt;a href="http://weblogs.asp.net/bradvincent/archive/2007/10/07/220-berutils-part-1-cryptography-continued.aspx" target="_blank" mce_href="http://weblogs.asp.net/bradvincent/archive/2007/10/07/220-berutils-part-1-cryptography-continued.aspx"&gt;Part 2 : Cryptography (Continued)&lt;/a&gt; - Encryption &lt;br&gt;&lt;/li&gt;

&lt;li&gt;&lt;a href="http://weblogs.asp.net/bradvincent/archive/2007/10/22/220-berutils-part-3-strings.aspx" target="_blank" mce_href="http://weblogs.asp.net/bradvincent/archive/2007/10/22/220-berutils-part-3-strings.aspx"&gt;Part 3 : Strings&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="/bradvincent/archive/2007/12/13/220-berutils-part-4-collections.aspx" target="_blank" mce_href="/bradvincent/archive/2007/12/13/220-berutils-part-4-collections.aspx"&gt;Part 4 : Collections&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;I figured it was about time I did another post in the UberUtils series seeing that I haven't written a post in over a month. So here is the next installment. This time it's for &lt;b&gt;collections&lt;/b&gt;. I hear you asking "but the framework has every collection I will ever need", and this is true for 98% of the time. But every once in a while there comes a time where I find myself subtly changing the way an existing collection works, or wishing it could do something just slightly differently. As with any software development, there are many different ways to solve the same problem, so you probably find
yourself getting around limitations with the built-in collections
without even knowing it. (I know I have when I go back and look at code I've written).&lt;/p&gt;

&lt;p&gt;The number one question I have found myself asking over the years with regards to the collection namespace is:&lt;/p&gt;

&lt;p&gt;&lt;b&gt;Is there a dictionary whereby I can access the values from both the key and an &lt;u&gt;index&lt;/u&gt;?&lt;/b&gt;&lt;/p&gt;

&lt;p&gt;The answer to this is NO. And if I'm wrong about this then please shoot me now for wasting so much time over the years on this code. You can overcome this limitation by using the other collections at your disposal, and with not so much code either. The thing is, I hate writing the same code over and over again (I actually refuse to do it), so why not write a generic dictionary that can access the values by index? And then just use that dictionary instead of the normal dictionary in the future. &lt;/p&gt;

&lt;p&gt;Introducing the &lt;b&gt;IndexedDictionary&lt;/b&gt;, an indexable dictionary. Here is a unit test to show the indexing feature :&lt;/p&gt;



&lt;pre class="csharpcode"&gt;        [TestMethod()]&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SomeTest()&lt;br&gt;        {&lt;br&gt;            IndexedDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt; col = &lt;span class="kwrd"&gt;new&lt;/span&gt; IndexedDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;,&lt;span class="kwrd"&gt;int&lt;/span&gt;&amp;gt;();&lt;br&gt;            col.Add(&lt;span class="str"&gt;"1"&lt;/span&gt;, 1);&lt;br&gt;            col.Add(&lt;span class="str"&gt;"2"&lt;/span&gt;, 2);&lt;br&gt;            col.AddAt(0, &lt;span class="str"&gt;"0"&lt;/span&gt;, 0);   &lt;span class="rem"&gt;//add by index&lt;/span&gt;&lt;br&gt;            col.Add(&lt;span class="str"&gt;"3"&lt;/span&gt;, 3);&lt;br&gt;            col.RemoveAt(2); //remove by index&lt;br&gt;            &lt;span class="kwrd"&gt;string&lt;/span&gt; strList = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Empty;&lt;br&gt;            &lt;span class="kwrd"&gt;for&lt;/span&gt; (&lt;span class="kwrd"&gt;int&lt;/span&gt; i = 0; i &amp;lt; col.Count; i++)&lt;br&gt;            {&lt;br&gt;                strList += col[i]; //get by index&lt;br&gt;            }&lt;br&gt;            Assert.AreEqual(strList, &lt;span class="str"&gt;"013"&lt;/span&gt;);&lt;br&gt;        }&lt;/pre&gt;
As you can see, you can access the dictionary now by an index (aswell as your key). This is accomplished simply by inheriting from the Dictionary class and holding a List inside the class too :
&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; IndexedDictionary&amp;lt;TKey, TValue&amp;gt; : Dictionary&amp;lt;TKey, TValue&amp;gt;&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;protected&lt;/span&gt; List&amp;lt;TKey&amp;gt; m_col = &lt;span class="kwrd"&gt;new&lt;/span&gt; List&amp;lt;TKey&amp;gt;();&lt;/pre&gt;
&lt;p&gt;
I have also added some extra features which can be toggled :&lt;br&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;u&gt;Replace Duplicate Keys&lt;/u&gt; - obviously you cannot have multiple entries in a dictionary with the same key, so what this does instead is replaces a value with the same key when adding to the collection&lt;/li&gt;
&lt;li&gt;&lt;u&gt;Throw Error On Invalid Remove&lt;/u&gt; - if disabled, when you try to remove an item that does not exist in the collection it just does nothing and does not throw an exception as it normally does&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Immediately after this new collection came the &lt;b&gt;NamedIndexedDictionary&lt;/b&gt;. This is a sub class of the IndexedDictionary class that takes a string as the key. &lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; NamedIndexedDictionary&amp;lt;TValue&amp;gt; : IndexedDictionary&amp;lt;&lt;span class="kwrd"&gt;string&lt;/span&gt;, TValue&amp;gt;&lt;/pre&gt;
&lt;p&gt;The string key can also be set to be case insensitive or not, so calling col["abc"] is the same as col["ABC"]. &lt;/p&gt;&lt;p&gt;Both have been very useful to me in the past and I hope someone else will find them useful too. Send me any other helpful collections you have created and I will add them too.&amp;nbsp;&lt;/p&gt;&lt;p&gt;Download here : &lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Code/collections.zip"&gt;collections.zip&lt;/a&gt;.&amp;nbsp;&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description><pubDate>Thu, 13 Dec 2007 11:30:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/220-berutils-part-4-collections</guid><category>.NET</category><category>.NET 3.5</category><category>C#</category><category>Free Code</category></item><item><title>Creating Extension Methods and Testing Them in VS2008</title><link>https://weblogs.asp.net:443/bradvincent/creating-extension-methods-and-testing-them-in-vs2008</link><description>&lt;p&gt;I wrote a beginners article on how to create your own extension methods in .NET 3.5 and then how to go about testing them using new built-in features in VS2008. Please go read the article at the Code Project : &lt;a href="http://www.codeproject.com/useritems/ExtensionUnitTests.asp" target="_blank" mce_href="http://www.codeproject.com/useritems/ExtensionUnitTests.asp"&gt;http://www.codeproject.com/useritems/ExtensionUnitTests.asp&lt;/a&gt;. &lt;/p&gt;&lt;p&gt;If you are interested in extension methods (like I am obviously) and plan on writing your own, I think the article is a good starting point. I give suggestions on when to use them and when I think it is not appropriate. I also talk about some &lt;a href="http://www.codeproject.com/useritems/ExtensionUnitTests.asp#Strange" target="_blank" mce_href="http://www.codeproject.com/useritems/ExtensionUnitTests.asp#Strange"&gt;unexpected behaviors&lt;/a&gt; that occur when using extension methods on variables that are null. It then walks you through a &lt;a href="http://www.codeproject.com/useritems/ExtensionUnitTests.asp#UnitTestinginVS2008" target="_blank" mce_href="http://www.codeproject.com/useritems/ExtensionUnitTests.asp#UnitTestinginVS2008"&gt;step by step guide&lt;/a&gt; on how to write unit tests for the extension methods using the new unit testing features of VS2008 pro. &lt;br&gt;&lt;/p&gt;&lt;p&gt;Please &lt;a href="http://www.codeproject.com/useritems/ExtensionUnitTests.asp" target="_blank" mce_href="http://www.codeproject.com/useritems/ExtensionUnitTests.asp"&gt;check it out&lt;/a&gt; and comment on how I could improve it and please remember to rate the article.&lt;/p&gt;</description><pubDate>Sun, 04 Nov 2007 20:13:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/creating-extension-methods-and-testing-them-in-vs2008</guid><category>.NET</category><category>.NET 3.5</category><category>C#</category><category>VS2008</category></item><item><title>ÜberUtils - Part 3 : Strings</title><link>https://weblogs.asp.net:443/bradvincent/220-berutils-part-3-strings</link><description>&lt;p&gt;ÜberUtils Series posts so far :&lt;br&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx" target="_blank" mce_href="/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx"&gt;Part 1 : Cryptography&lt;/a&gt; - Hashing&lt;/li&gt;
&lt;li&gt;&lt;a href="/bradvincent/archive/2007/10/07/220-berutils-part-1-cryptography-continued.aspx" target="_blank" mce_href="/bradvincent/archive/2007/10/07/220-berutils-part-1-cryptography-continued.aspx"&gt;Part 2 : Cryptography (Continued)&lt;/a&gt; - Encryption &lt;br&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/bradvincent/archive/2007/10/22/220-berutils-part-3-strings.aspx" target="_blank" mce_href="/bradvincent/archive/2007/10/22/220-berutils-part-3-strings.aspx"&gt;Part 3 : Strings&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="/bradvincent/archive/2007/12/13/220-berutils-part-4-collections.aspx" target="_blank" mce_href="/bradvincent/archive/2007/12/13/220-berutils-part-4-collections.aspx"&gt;Part 4 : Collections&lt;/a&gt;&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So every developer has (or should have) a utilities class for strings. It seems the built-in string class never has enough (well for me in any case). So I hereby introduce my string utils class. It actually comprises of 3 files which are :&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;Strings.cs (the actual string utils)&lt;br&gt;&lt;/li&gt;
&lt;li&gt;SafeConvert.cs (a class for doing common conversions)&lt;/li&gt;
&lt;li&gt;Extensions/Strings.cs (extension methods using the string utils)&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;Here is the class diagram of the Strings class : &lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/class_Strings.gif" mce_href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/class_Strings.gif"&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/class_Strings.gif" mce_src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/class_Strings.gif" border="0"&gt;&lt;/a&gt;&lt;/b&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;As you can see it has a nested class Regex which is also static. More on this later. Lets cover the string utility methods first (in 'logical' order):&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;IsEmpty&lt;/b&gt; - returns true if the object passed in is either null or has a length of zero (exactly like string.isNullOrEmpty but can take an object as input)&lt;/li&gt;
&lt;li&gt;&lt;b&gt;IsNumeric &lt;/b&gt;- returns true if we are dealing with a numeric value. Uses the regular expression : @"^\-?\(?([0-9]{0,3}(\,?[0-9]{3})*(\.?[0-9]*))\)?$". This matches a positive or negative value with any precision and scale (whole number or decimal). It also allows for left-padded zeros, commas as group separators or parenthesis to indicate negative number&lt;/li&gt;
&lt;li&gt;&lt;b&gt;IsEmail&lt;/b&gt; - returns true if an email. Uses the regular expression : @"([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)"&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Trim&lt;/b&gt; - exactly like "abc".Trim() but adds checking for nulls&lt;/li&gt;
&lt;li&gt;&lt;b&gt;CutWhitespace&lt;/b&gt; - cuts all whitespace from a string aswell as trims it&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.CutWhitespace(" 12&amp;nbsp; 34&amp;nbsp;&amp;nbsp; 5 6&amp;nbsp; 7&amp;nbsp;&amp;nbsp; ") == "12 34 5 6 7"&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b&gt;CutEnd &lt;/b&gt;- chops the end &lt;i&gt;n &lt;/i&gt;chars off the end of a string&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.CutEnd("1234567890", 3) == "1234567"&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b&gt;CutStart&lt;/b&gt; - chops the first &lt;i&gt;n&lt;/i&gt; chars off the beginning of a string&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.CutStart("1234567890", 3) == "4567890"&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b&gt;Start&lt;/b&gt; - returns the first &lt;i&gt;n&lt;/i&gt; chars of a string&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.Start("1234567890", 3) == "123"&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b&gt;End&lt;/b&gt; - returns the last &lt;i&gt;n&lt;/i&gt; chars of a string&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.End("1234567890", 3) == "890"&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b&gt;GetOccurences&lt;/b&gt; - returns an array of strings that are found within another string based on a regular expression&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.GetOccurences("say day bay toy", "[sdbt]ay") == new string[] {"say" , "day" , "bay"}&lt;/li&gt;
&lt;li&gt;eg. Strings.GetOccurences("123asdasd 1sk 555 sdkfjsdfkl999", "\\d+") == new string [] {"123" , "1" , "555" , "999"}&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b&gt;OccurenceCount&lt;/b&gt; - returns the count of strings found within another string based on a regular expression&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.OccurenceCount("the cat sat on the mat", "at") == 3&lt;/li&gt;
&lt;li&gt;eg. Strings.OccurenceCount("abcabc", "a") == 2&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;strike&gt;&lt;b&gt;Combine&lt;/b&gt; - combines a string array by a delimeter (or not)&lt;/strike&gt; (DEPRICATED - read update and comments)&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strike&gt;eg. Strings.Combine(Strings.GetOccurences("123asdasd 1sk 555 sdkfjsdfkl999", "\\d+"), ",") == "123,1,555,999"&lt;/strike&gt;&lt;/li&gt;
&lt;li&gt;&lt;strike&gt;eg. Strings.Combine(new string[] { "a", "b", "c", "d" }, ";") == "a;b;c;d"&lt;/strike&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;strike&gt;&lt;b&gt;ToPaddedNumber&lt;/b&gt; - returns a zero padded number&lt;/strike&gt; (DEPRICATED - read update and comments)&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;&lt;strike&gt;eg. Strings.ToPaddedNumber("123", 5) == "00123"&lt;/strike&gt;&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b&gt;XOR&lt;/b&gt; - performs a binary XOR operation on each char in the input string based on a key. Very simple form of encryption where XOR(XOR(input)) == input&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.XOR(Strings.XOR("test", "key"), "key") == "test"&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b&gt;ToTitleCase&lt;/b&gt; - returns the title case of a string&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.ToTitleCase("this is a title") == "This Is A Title"&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b&gt;ToFriendlyName&lt;/b&gt; - returns what I call a "friendly" version of a string. I use this mainly for converting a database field name into a user friendly name&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.ToFriendlyName("IAmNotFriendly") == "I Am Not Friendly"&lt;/li&gt;
&lt;li&gt;eg. Strings.ToFriendlyName("SomePrimaryKeyId") == "Some Primary Key"&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;p&gt;Now onto the Regex class. The static Regex class just wraps regular expression functionality and contains a few commonly used expressions as constants. Here is the run down :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&amp;nbsp;&lt;b&gt;IsExactMatch&lt;/b&gt; - returns true if a string is an exact match for a pattern&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.Regex.IsExactMatch("test@google.com", Strings.Regex.REGEX_EMAIL) == true&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b&gt;Contains&lt;/b&gt; - returns true if a string contains a pattern&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.Regex.Contains("here is my email : test@google.com", Strings.Regex.REGEX_EMAIL) == true&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b&gt;Replace&lt;/b&gt; - returns a string with a pattern replaced by another string&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.Regex.Replace("1 23 a 456", @"\d+", "!") == "! ! a !"&lt;/li&gt;
&lt;/ul&gt;
&lt;li&gt;&lt;b&gt;GetMatch&lt;/b&gt; - returns the first match of pattern within a string&lt;/li&gt;
&lt;ul&gt;
&lt;li&gt;eg. Strings.Regex.GetMatch("Subject: Test Subject\r\n", @"Subject\s*\:\s*(?&amp;lt;SubjectReturn&amp;gt;.*)\r\n", "SubjectReturn") == "Text Subject"&lt;/li&gt;
&lt;/ul&gt;
&lt;/ul&gt;
&lt;p&gt;Now onto the SafeConvert class. It contains the following methods :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;ToBoolean&lt;/b&gt; - returns a boolean value from an object&lt;/li&gt;
&lt;li&gt;&lt;b&gt;ToInt&lt;/b&gt; - returns an integer value from an object&lt;/li&gt;
&lt;li&gt;&lt;b&gt;ToDecimal&lt;/b&gt; - returns a decimal value from an object&lt;/li&gt;
&lt;li&gt;&lt;b&gt;ToDouble&lt;/b&gt; - returns a double value from an object&lt;/li&gt;
&lt;li&gt;&lt;b&gt;ToHexString&lt;/b&gt; - returns a hexidecimal string representation of a byte array. This is used from Extensions\ByteArray.cs&lt;/li&gt;
&lt;li&gt;&lt;b&gt;ToStream&lt;/b&gt; - returns a System.IO.MemoryStream from a string &lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;So thats version 1 of the strings utilities. I say version 1 because I will no doubt add to this over the next couple of posts. &lt;/p&gt;
&lt;p&gt;Oh yes, and again we have a whole bunch of new extension methods :&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;b&gt;Start&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;End&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;CutStart&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;CutEnd&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;OccurenceCount&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;GetOccurences&lt;/b&gt;&lt;/li&gt;
&lt;li&gt;&lt;b&gt;ReplaceAll &lt;/b&gt;- similar to Replace, but uses a regular expression to do the replacement&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Split - &lt;/b&gt;similar to Split(char c) but takes a string pattern to split using regular expressions&lt;/li&gt;
&lt;li&gt;&lt;strike&gt;&lt;b&gt;Combine&lt;/b&gt;&lt;/strike&gt; (DEPRICATED - read update and comments)&lt;/li&gt;
&lt;li&gt;&lt;b&gt;Join&lt;/b&gt; - an extension method for string arrays wrapping the string.Join method&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Now I know some people might argue that this is extension method abuse, but look at how much more power my strings have :&lt;/p&gt;
&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/stringExtensions.gif"&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/stringExtensions.gif" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;... and anything that helps me code quicker and smarter is not abuse in my book - its smart coding!&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Code/Utils_ver3.zip"&gt;Download the source code and unit tests here&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;b&gt;UPDATE&lt;/b&gt;&lt;/i&gt; - thanks to &lt;a href="http://blogs.ipona.com/dan" target="_blank" mce_href="http://blogs.ipona.com/dan"&gt;Dan's&lt;/a&gt; comments we found a bug in the email regular expression whereby it would not allow the domain ".museum" so I changed the regex to &lt;br&gt;@"([\w-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([\w-]+\.)+))([a-zA-Z]{2,&lt;b&gt;8&lt;/b&gt;}|[0-9]{1,&lt;b&gt;8&lt;/b&gt;})(\]?)" (changes in bold)&lt;br&gt;Please note that email validation seems to be a touchy point for many developers as can be seen over at &lt;a href="http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx" target="_blank" mce_href="http://haacked.com/archive/2007/08/21/i-knew-how-to-validate-an-email-address-until-i.aspx"&gt;haaked.com&lt;/a&gt; . I would suggest not to use &lt;b&gt;ANY&lt;/b&gt; email validation like this for &lt;b&gt;restricting&lt;/b&gt; comments or purchases online, as you would be limiting your site's reach. Source code and unit tests have been updated.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;b&gt;UPDATE&lt;/b&gt;&lt;/i&gt; - thanks to&amp;nbsp;&lt;a onclick="return top.js.OpenExtLink(window,event,this)" href="http://www.hanselman.com/blog" target="_blank"&gt;Scott Hanselman&lt;/a&gt; for pointing out that ToPaddedNumber is redundant as the string class has a &lt;b&gt;PadLeft&lt;/b&gt; (as well a PadRight) method - DOH! Source code and unit tests have been updated.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;b&gt;UPDATE&lt;/b&gt;&lt;/i&gt; - thanks to Don and &lt;a href="http://www.johnmeyer.net/blog" target="_blank" mce_href="http://www.johnmeyer.net/blog"&gt;John&lt;/a&gt; for pointing out the fact that my Combine method is redundant as the string.Join method does the exact same thing. - oops ;) &lt;br&gt;I then renamed my extension method &lt;i&gt;Combine&lt;/i&gt; to &lt;i&gt;Join&lt;/i&gt; and changed it to wrap the string.Join functionality. Again Source and tests have been updated.&lt;/p&gt;
&lt;p&gt;&lt;i&gt;&lt;b&gt;NOTE&lt;/b&gt;&lt;/i&gt; - I renamed the static extension classes so that you could include both the &lt;i&gt;Utils&lt;/i&gt; and &lt;i&gt;Utils.Extensions&lt;/i&gt; namespaces without getting the build error : &lt;i&gt;'Strings' is an ambiguous reference between 'Utils.Strings' and 'Utils.Extensions.Strings'. &lt;/i&gt;Please get the latest source.&lt;br&gt;&lt;/p&gt;
&lt;p&gt;&lt;br&gt;Thanks for all comments and feedback and please keep it coming. Collaboration and a LOT of testing is the only way to produce robust,useful code!&lt;br&gt;&lt;/p&gt;</description><pubDate>Mon, 22 Oct 2007 18:52:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/220-berutils-part-3-strings</guid><category>.NET</category><category>.NET 3.5</category><category>Free Code</category><category>Utils</category></item><item><title>Hello Silverlight - Start Your Silverlight Journey Today!</title><link>https://weblogs.asp.net:443/bradvincent/hello-silverlight-start-your-silverlight-journey-today</link><description>&lt;p&gt;I think today is the start for great things to come. And why? Because I had my first article published today, thats why! You can find it over at Dotnetslackers : &lt;a href="http://dotnetslackers.com/articles/silverlight/HelloSilverlightStartYourSilverlightJourneyToday.aspx" target="_blank" mce_href="http://dotnetslackers.com/articles/silverlight/HelloSilverlightStartYourSilverlightJourneyToday.aspx"&gt;http://dotnetslackers.com&lt;/a&gt;&lt;wbr&gt;&lt;a href="http://dotnetslackers.com/articles/silverlight/HelloSilverlightStartYourSilverlightJourneyToday.aspx" target="_blank" mce_href="http://dotnetslackers.com/articles/silverlight/HelloSilverlightStartYourSilverlightJourneyToday.aspx"&gt;/articles/silverlight/HelloSilv&lt;/a&gt;&lt;wbr&gt;&lt;a href="http://dotnetslackers.com/articles/silverlight/HelloSilverlightStartYourSilverlightJourneyToday.aspx" target="_blank" mce_href="http://dotnetslackers.com/articles/silverlight/HelloSilverlightStartYourSilverlightJourneyToday.aspx"&gt;erlightStartYourSilverlightJour&lt;/a&gt;&lt;wbr&gt;&lt;a href="http://dotnetslackers.com/articles/silverlight/HelloSilverlightStartYourSilverlightJourneyToday.aspx" target="_blank" mce_href="http://dotnetslackers.com/articles/silverlight/HelloSilverlightStartYourSilverlightJourneyToday.aspx"&gt;neyToday.aspx&lt;/a&gt;. It basically is the walk through I was looking for when I was curious about Silverlight, but could never find. &lt;/p&gt;&lt;p&gt;It discusses what you need to start developing in Silverlight, what makes up your average Silverlight project, and walks you through a simple example.&lt;/p&gt;&lt;p&gt;If you found my article useful, I also found another good Silverlight article today at the codeproject :&amp;nbsp; &lt;a href="http://www.codeproject.com/silverlight/BeginningSilverlightPart1.asp" target="_blank" mce_href="http://www.codeproject.com/silverlight/BeginningSilverlightPart1.asp"&gt;http://www.codeproject.com/silverlight/BeginningSilverlightPart1.asp&lt;/a&gt;&lt;/p&gt;&lt;p&gt;happy coding&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;b&gt;Update :&lt;/b&gt;&amp;nbsp; &lt;br&gt;Ever wondered how you can render HTML in your silverlight controls? &lt;a href="http://blogs.msdn.com/delay/default.aspx" target="_blank" mce_href="http://blogs.msdn.com/delay/default.aspx"&gt;Delay&lt;/a&gt; has written an HTMLTextBlock control that does just that. Obviously it does not have a fully fledged HTML rendering engine behind the scenes, but it supports the more common tags. &lt;a href="http://blogs.msdn.com/delay/archive/2007/09/24/bringing-more-html-to-silverlight-htmltextblock-improvements.aspx" target="_blank" mce_href="http://blogs.msdn.com/delay/archive/2007/09/24/bringing-more-html-to-silverlight-htmltextblock-improvements.aspx"&gt;Check it out&lt;/a&gt;.&lt;br&gt;&amp;nbsp;&lt;/p&gt;</description><pubDate>Tue, 16 Oct 2007 17:25:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/hello-silverlight-start-your-silverlight-journey-today</guid><category>.NET</category><category>Silverlight</category></item><item><title>ÜberUtils - Part 2 : Cryptography (continued)</title><link>https://weblogs.asp.net:443/bradvincent/220-berutils-part-1-cryptography-continued</link><description>&lt;p&gt;ÜberUtils Series posts so far :&lt;br&gt;&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx" target="_blank" mce_href="/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx"&gt;Part 1 : Cryptography&lt;/a&gt; - Hashing&lt;/li&gt;
&lt;li&gt;&lt;a href="/bradvincent/archive/2007/10/07/220-berutils-part-1-cryptography-continued.aspx" target="_blank" mce_href="/bradvincent/archive/2007/10/07/220-berutils-part-1-cryptography-continued.aspx"&gt;Part 2 : Cryptography (Continued)&lt;/a&gt; - Encryption &lt;br&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="/bradvincent/archive/2007/10/22/220-berutils-part-3-strings.aspx" target="_blank" mce_href="/bradvincent/archive/2007/10/22/220-berutils-part-3-strings.aspx"&gt;Part 3 : Strings&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://weblogs.asp.net/bradvincent/archive/2007/12/13/220-berutils-part-4-collections.aspx" target="_blank" mce_href="/bradvincent/archive/2007/12/13/220-berutils-part-4-collections.aspx"&gt;Part 4 : Collections&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;I am now going to finish off the cryptography part of my ÜberUtils project. If you don't know about it, &lt;a href="/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx" mce_href="/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx"&gt;check it out&lt;/a&gt;. In the first article I released the hashing class. This post I am going to run through the Encryption class. The Encryption class is pretty straight forward and basically wraps the System.Security.Cryptography symmetric encryption classes. Here are the types of encryption available (this is exposed as an enum):&lt;br&gt;&lt;br&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;enum&lt;/span&gt; EncryptionTypes&lt;br&gt;{&lt;br&gt;   DES,&lt;br&gt;   RC2,&lt;br&gt;   Rijndael,&lt;br&gt;   TripleDES&lt;br&gt;}&lt;/pre&gt;
&lt;p&gt;
A simple example demostrates the ease of use :
&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Encryption target = &lt;span class="kwrd"&gt;new&lt;/span&gt; Encryption();&lt;br&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; inputText = &lt;span class="str"&gt;"Thi$ is @ str!&amp;amp;n to tEst encrypti0n!"&lt;/span&gt;;&lt;br&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; output = target.Encrypt(inputText);&lt;/pre&gt;

&lt;p&gt;You can also call a static method to make it even easier : &lt;br&gt;&lt;/p&gt;
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; strCiperText = Encryption.EncryptText(&lt;span class="str"&gt;"hello world!"&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;You can also as easily change the encryption algorithm, the &lt;a href="http://en.wikipedia.org/wiki/Key_%28cryptography%29" target="_blank" mce_href="http://en.wikipedia.org/wiki/Key_%28cryptography%29"&gt;password key&lt;/a&gt; or the &lt;a href="http://en.wikipedia.org/wiki/Salt_%28cryptography%29" target="_blank" mce_href="http://en.wikipedia.org/wiki/Salt_%28cryptography%29"&gt;salt&lt;/a&gt;. I am not going to write an article explaining how encryption works and
what the different components are. If you are interested, check out this &lt;a href="http://www.vbdotnetheaven.com/UploadFile/gsparamasivam/cryp04112005063256AM/cryp.aspx" target="_blank" mce_href="http://www.vbdotnetheaven.com/UploadFile/gsparamasivam/cryp04112005063256AM/cryp.aspx"&gt;nice article&lt;/a&gt; I found on the subject. &lt;/p&gt;

&lt;p&gt;You guessed it, it is as simple to decrypt too :&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; strOriginal = Encryption.DecryptText(strEncryptedText);&lt;/pre&gt;
&lt;p&gt;Here is the class diagram :&lt;/p&gt;

&lt;p&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/class_encryption.gif"&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/class_encryption.gif" border="0"&gt;&lt;/a&gt;&amp;nbsp;&lt;/p&gt;

&lt;p&gt;Like the hashing class, the encryption class also uses some extension methods. Please note : extension methods should only be used when extending functionality of an existing class in a reusable fashion. &lt;b&gt;Don't create an extension method just because you can&lt;/b&gt;, create one when you see yourself using the method over and over again in many places. This is my reasoning behind creating these extension methods. I feel they will be reused again in the future and it makes my life as a developer easier. Here they are :&lt;/p&gt;

&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ToBase64String(&lt;span class="kwrd"&gt;this&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] data)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; Convert.ToBase64String(data);&lt;br&gt;        }&lt;br&gt;        &lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ToUTF8String(&lt;span class="kwrd"&gt;this&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] data)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; UTF8Encoding().GetString(data);&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] ToByteArrayUTF8(&lt;span class="kwrd"&gt;this&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; str)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; &lt;span class="kwrd"&gt;new&lt;/span&gt; UTF8Encoding().GetBytes(str);&lt;br&gt;        }&lt;br&gt;&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] ToByteArrayBase64(&lt;span class="kwrd"&gt;this&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; str)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; Convert.FromBase64String(str);&lt;br&gt;        }&lt;/pre&gt;
&lt;p&gt;&amp;nbsp;So thats the encryption class. Included in the source, we again add unit tests for encryption. Download the &lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Code/Utils_ver2.zip"&gt;source here&lt;/a&gt;. Enjoy.&lt;br&gt;&lt;/p&gt;
</description><pubDate>Sun, 07 Oct 2007 19:35:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/220-berutils-part-1-cryptography-continued</guid><category>.NET</category><category>.NET 3.5</category><category>C#</category><category>Free Code</category></item><item><title>.NET framework source to be released</title><link>https://weblogs.asp.net:443/bradvincent/net-framework-source-to-be-released</link><description>&lt;p&gt;Well if you havent heard the good news already, then go read about it here at ScuttGu's Blog : &lt;a href="/scottgu/archive/2007/10/03/releasing-the-source-code-for-the-net-framework-libraries.aspx" target="_blank" mce_href="/scottgu/archive/2007/10/03/releasing-the-source-code-for-the-net-framework-libraries.aspx"&gt;Releasing the Source Code for the .NET Framework Libraries&lt;/a&gt; . As the name of the article implies, Microsoft is planning to release a standalone install that contains the .NET Framework source libraries. It will also include integrated debugging support within VS2008. &lt;/p&gt;
&lt;p&gt;WOW!!!!&lt;/p&gt;
&lt;p&gt;If you develop using .NET there must have been a time when you needed to delve into the framework code. Thank goodness for the &lt;a href="http://www.aisto.com/roeder/dotnet/" target="_blank" mce_href="http://www.aisto.com/roeder/dotnet/"&gt;Reflector&lt;/a&gt; tool written by Lutz Roeder. It has been the only way to see what the framework is actually doing, by decompiling the framework code:&lt;br&gt;&lt;a href="http://weblogs.asp.net/blogs/bradvincent/reflector1.gif"&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/reflector1.gif" border="0"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Or, if you're like me and you want to view the code within VS, then you can download Denis Bauer's Reflector add-in &lt;a href="http://www.denisbauer.com/NETTools/FileDisassembler.aspx" target="_blank" mce_href="http://www.denisbauer.com/NETTools/FileDisassembler.aspx"&gt;Reflector.FileDisassembler&lt;/a&gt; . This allows you to dump a whole framework DLL or single class to a file so you can play :&lt;br&gt;&lt;a href="http://weblogs.asp.net/blogs/bradvincent/reflector2.gif"&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/reflector2.gif" border="0"&gt;&lt;/a&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;OK, back to the topic - .NET FRAMEWORK SOURCE CODE! Go check out ScottGu's post which shows him stepping through the code within VS2008. &lt;/p&gt;
&lt;p&gt;Another amazing feature he talks about is the ability to step into the source even if you haven't downloaded the source. Just step into a framework method and &lt;b&gt;VS2008 will automatically download the appropriate source file from Microsoft&lt;/b&gt;. All built in! Pretty awesome.&lt;/p&gt;
</description><pubDate>Thu, 04 Oct 2007 06:17:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/net-framework-source-to-be-released</guid><category>.NET</category><category>.NET 3.5</category></item><item><title>ÜberUtils - Part 1 : Cryptography</title><link>https://weblogs.asp.net:443/bradvincent/uber-utils-part-1-cryptography</link><description>&lt;p&gt;ÜberUtils Series posts so far :&lt;br&gt;&lt;/p&gt;&lt;ul&gt;&lt;li&gt;&lt;a href="/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx" target="_blank" mce_href="/bradvincent/archive/2007/10/02/uber-utils-part-1-cryptography.aspx"&gt;Part 1 : Cryptography&lt;/a&gt; - Hashing&lt;/li&gt;&lt;li&gt;&lt;a href="/bradvincent/archive/2007/10/07/220-berutils-part-1-cryptography-continued.aspx" target="_blank" mce_href="/bradvincent/archive/2007/10/07/220-berutils-part-1-cryptography-continued.aspx"&gt;Part 2 : Cryptography (Continued)&lt;/a&gt; - Encryption &lt;br&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="/bradvincent/archive/2007/10/22/220-berutils-part-3-strings.aspx" target="_blank" mce_href="/bradvincent/archive/2007/10/22/220-berutils-part-3-strings.aspx"&gt;Part 3 : Strings&lt;/a&gt;&lt;/li&gt;&lt;li&gt;&lt;a href="http://weblogs.asp.net/bradvincent/archive/2007/12/13/220-berutils-part-4-collections.aspx" target="_blank" mce_href="/bradvincent/archive/2007/12/13/220-berutils-part-4-collections.aspx"&gt;Part 4 : Collections&lt;/a&gt;&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;If you read my &lt;a href="/bradvincent/archive/2007/09/27/lets-play-catchup-bigtime.aspx" mce_href="/bradvincent/archive/2007/09/27/lets-play-catchup-bigtime.aspx"&gt;previous post&lt;/a&gt;, you would know that it is my time to give back to the community. So where should you start when creating the &lt;b&gt;ULTIMATE REUSABLE UTILS CLASS LIBRARY&lt;/b&gt;? (from now on called &lt;i&gt;&lt;a href="http://en.wikipedia.org/wiki/%C3%9Cber" mce_href="http://en.wikipedia.org/wiki/%C3%9Cber"&gt;Über&lt;/a&gt;Utils&lt;/i&gt;)?&amp;nbsp;Good question, and thats the reason why its taken me a while to start this series, cause I had to start it at exactly the right point. I thought back to the first utils class I wrote back in 2003 in .NET 1.1. It was a cryptography class that wrapped existing functionality that exists in the &lt;i&gt;system.security.cryptography&lt;/i&gt; namespace. &lt;br&gt;So I figure thats a good place to start again. But first I wanna note a few things :&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;This code will be written for .NET 3.5 framework (this is to take advantage of the newer features)&lt;br&gt;&lt;/li&gt;

&lt;li&gt;I will be using VS2008 beta 2 which, which at this point in time (Oct 2007), you can &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=b98a61ba-99b0-40b7-ab6e-5386a2b94217&amp;amp;DisplayLang=en" mce_href="http://www.microsoft.com/downloads/details.aspx?FamilyID=b98a61ba-99b0-40b7-ab6e-5386a2b94217&amp;amp;DisplayLang=en"&gt;download for free&lt;/a&gt;. (I want to utilise some of the new features available e.g. Unit Testing)&lt;/li&gt;

&lt;li&gt;The namespaces I use will be as simple and generic as possible, meaning that it will be simple to incorporate into any number of companies / projects / systems / architectures etc. I hate having weird long namespaces when I use other developers libraries. I would prefer a namespace like "Utils" rather than "BradVin.Core.Utils". Wouldnt you agree? (I was also thinking about using "System.Utils")&lt;br&gt;&lt;/li&gt;

&lt;li&gt;The project files and code can be downloaded from codeplex at the &lt;a href="http://www.codeplex.com/UberUtils" target="_blank" mce_href="http://www.codeplex.com/UberUtils"&gt;ÜberUtils project page&lt;/a&gt;. &lt;/li&gt;

&lt;li&gt;Code license : &lt;a href="http://creativecommons.org/licenses/publicdomain/" mce_href="http://creativecommons.org/licenses/publicdomain/"&gt;public domain&lt;/a&gt;. This means that all the code in this series is absolutely free, and by definition : the code &lt;i&gt;may be freely reproduced, distributed, transmitted, used, modified,
built upon, or otherwise exploited by anyone for any purpose,
commercial or non-commercial, and in any way, including by methods that
have not yet been invented or conceived&lt;/i&gt;. So rip it to pieces, pull out what you like - I DONT CARE! My only stipulation is this : &lt;b&gt;IF YOU ADD SOMETHING USEFUL PLEASE SHARE IT WITH US!!!!! &lt;/b&gt;(you can do this by commenting on this blog or on discussing it at code plex)&lt;br&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;&lt;br&gt;I'm gonna start with a Hashing class which is extremely simple to use. This class makes it easy to hash a byte array or a string e.g.&lt;br&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; strHash = Hashing.Hash(&lt;span class="str"&gt;"test"&lt;/span&gt;);&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;You can also use different hashing algorithms e.g.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; strHash = Hashing.Hash(&lt;span class="str"&gt;"test"&lt;/span&gt;, Hashing.HashingTypes.SHA512);&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;Internally, the different hashing algorithm classes used are :
SHA1CryptoServiceProvider, SHA256Managed, SHA384Managed, SHA512Managed
and the default MD5CryptoServiceProvider. &lt;/p&gt;

&lt;p&gt;Very simple isn't it?. Here is the class diagram :&lt;br&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/class_hashing.jpg"&gt;&lt;/a&gt;&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/class_hashing.gif"&gt;&lt;img src="https://aspblogs.blob.core.windows.net/media/bradvincent/Media/class_hashing.gif" border="0"&gt;&lt;/a&gt;&lt;br&gt;&lt;/p&gt;

&lt;p&gt;If you have a look at the code, you would have noticed some strange new methods on both string and byte array. This is using a new .NET 3.5 feature called &lt;b&gt;extension methods&lt;/b&gt;. If you've not heard of it yet, the best explanation is by ScottGu &lt;a href="/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx" target="_blank" mce_href="/scottgu/archive/2007/03/13/new-orcas-language-feature-extension-methods.aspx"&gt;here&lt;/a&gt;. Infinities Loop also talks about it &lt;a href="/infinitiesloop/archive/2007/09/25/response-redirect-into-a-new-window-with-extension-methods.aspx" aiotitle="here" target="_blank" mce_href="/infinitiesloop/archive/2007/09/25/response-redirect-into-a-new-window-with-extension-methods.aspx"&gt;here&lt;/a&gt; and ScottGu again &lt;a href="/scottgu/archive/2007/10/01/tip-trick-building-a-tojson-extension-method-using-net-3-5.aspx" aiotitle="here" target="_blank" mce_href="/scottgu/archive/2007/10/01/tip-trick-building-a-tojson-extension-method-using-net-3-5.aspx"&gt;here&lt;/a&gt; . So let's see how I implement my extension methods. Check this code out :&lt;br&gt;
&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;private&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ComputeHash(&lt;span class="kwrd"&gt;string&lt;/span&gt; inputText)&lt;br&gt;{&lt;br&gt;     &lt;span class="rem"&gt;//convert output byte array to a string&lt;/span&gt;&lt;br&gt;     &lt;span class="kwrd"&gt;return&lt;/span&gt; ComputeHash(inputText.ToByteArray()).ToHexString().ToUpper();&lt;br&gt;}&lt;/pre&gt;You'll see a string has a new method called ToByteArray. Also note that the ComputeHash method returns a byte array, and this means that a byte array now has a new method too : ToHexString. Here is the code for these 2 extension methods :
&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Utils.Extensions&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; ByteArrays&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; ToHexString(&lt;span class="kwrd"&gt;this&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] data)&lt;br&gt;        {&lt;br&gt;            StringBuilder sb = &lt;span class="kwrd"&gt;new&lt;/span&gt; StringBuilder(data.Length * 2);&lt;br&gt;            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (&lt;span class="kwrd"&gt;byte&lt;/span&gt; b &lt;span class="kwrd"&gt;in&lt;/span&gt; data)&lt;br&gt;            {&lt;br&gt;                sb.AppendFormat(&lt;span class="str"&gt;"{0:x2}"&lt;/span&gt;, b);&lt;br&gt;            }&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; sb.ToString();&lt;br&gt;        }&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;byte&lt;/span&gt;[] ToByteArray(&lt;span class="kwrd"&gt;this&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; str)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; ASCIIEncoding.ASCII.GetBytes(str);&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;/pre&gt;
&lt;p&gt;Now all I had to do to use these methods was add a using at the top of my class :&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; Utils.Extensions;&lt;/pre&gt;
&lt;p&gt;But I didn't want to just stop here. I've had a scenario in the past when I needed to compute a MD5 hash of a string. I also found &lt;a href="http://blog.stevex.net/index.php/c-code-snippet-creating-an-md5-hash-string/" target="_blank" mce_href="http://blog.stevex.net/index.php/c-code-snippet-creating-an-md5-hash-string/"&gt;this blog post&lt;/a&gt; on the subject and decided I can now use extension methods to add this functionality to every string. So heres the code :&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;namespace&lt;/span&gt; Utils.Extensions&lt;br&gt;{&lt;br&gt;    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;class&lt;/span&gt; Cryptography&lt;br&gt;    {&lt;br&gt;        &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; GetMD5HashCode(&lt;span class="kwrd"&gt;this&lt;/span&gt; &lt;span class="kwrd"&gt;string&lt;/span&gt; str)&lt;br&gt;        {&lt;br&gt;            &lt;span class="kwrd"&gt;return&lt;/span&gt; Utils.Cryptography.Hashing.Hash(str);&lt;br&gt;        }&lt;br&gt;    }&lt;br&gt;}&lt;br&gt;&lt;/pre&gt;
&lt;p&gt;So now I can use it on any string e.g. &lt;br&gt;&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;string&lt;/span&gt; actual = &lt;span class="str"&gt;"test"&lt;/span&gt;.GetMD5HashCode();&lt;br&gt;&lt;/pre&gt;So thats the Hashing class. This post ended up a lot longer than I expected, so in my next post Im going to add an encryption class. Please check out the code (&lt;a href="https://aspblogs.blob.core.windows.net/media/bradvincent/Code/Utils_ver1.zip"&gt;Download here&lt;/a&gt; or get it from my &lt;a href="http://www.codeplex.com/UberUtils/Release/ProjectReleases.aspx" target="_blank" mce_href="http://www.codeplex.com/UberUtils/Release/ProjectReleases.aspx"&gt;CodePlex project page&lt;/a&gt;). Included in the source are unit tests that check the hashing is doing its job correctly. (I used the&amp;nbsp; &lt;i&gt;System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile&lt;/i&gt; method to make sure the tests are valid and double checked the results against other non-C# hashing algorithms e.g. &lt;a href="http://pajhome.org.uk/crypt/md5/" target="_blank" mce_href="http://pajhome.org.uk/crypt/md5/"&gt;http://pajhome.org.uk/crypt/md5/&lt;/a&gt; )&lt;br&gt;
&lt;p&gt;&amp;nbsp;
&lt;/p&gt;
</description><pubDate>Tue, 02 Oct 2007 17:37:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/uber-utils-part-1-cryptography</guid><category>.NET</category><category>.NET 3.5</category><category>C#</category><category>Free Code</category></item><item><title>lets play catchup - BIGTIME!!!</title><link>https://weblogs.asp.net:443/bradvincent/lets-play-catchup-bigtime</link><description>&lt;p&gt;OK, so Ive got my blog up (FINALLY!!!). Well better late than never, and when Joe Stagner from &lt;a href="http://joeon.net/" title="Joe on .NET" target="_blank" mce_href="http://joeon.net/"&gt;http://joeon.net&lt;/a&gt; offered me a blog on ASP.NET I jumped at the offer. So thanks Joe!&lt;br&gt; &lt;/p&gt;&lt;p&gt;So here is my first post (of many I can assure you), BUT I have some serious catchup work to do. I mean, lets face it, I'm a couple years of posts behind. So where do I begin? Well to be honest I'm not quite sure myself, but I figured I should try start things off with a BANG! So I'm going to start with a series of code freebie give aways. &lt;/p&gt;&lt;p&gt;This first series of posts will be all about creating the &lt;b&gt;ULTIMATE REUSABLE UTILITY CLASS LIBRARY&lt;/b&gt;, and will contain code that I have put together over the years that I have found useful in my everyday coding. Here are some areas we will cover :&lt;/p&gt;&lt;ul&gt;&lt;li&gt;text / string utils&lt;/li&gt;&lt;li&gt;ConfigurationManager utils (app settings and connection strings)&lt;/li&gt;&lt;li&gt;Loging utils&lt;/li&gt;&lt;li&gt;Cryptography utils&lt;/li&gt;&lt;li&gt;File IO utils&lt;/li&gt;&lt;li&gt;Compression utils&lt;/li&gt;&lt;li&gt;Collection utils&lt;/li&gt;&lt;li&gt;etc&lt;/li&gt;&lt;/ul&gt;&lt;p&gt;Thats all I can think of for now, but the list will get bigger. A point I want to stress throughout this series (and blog) is &lt;b&gt;COLLABORATION&lt;/b&gt;. I built up these utils (and most of my code) from code others have shared on the net, so this is my turn to give back to the community. I believe that by collaborating and working together we can build some awesome stuff!!&lt;/p&gt;&lt;p&gt;&amp;nbsp;So having said that - over the next few weeks I want to chronicle the creation of the ULTIMATE REUSABLE UTILITY CLASS LIBRARY, and I want your feeback and hopefully additions to make it an UBER Utils library!!&lt;br&gt;&amp;nbsp;&lt;/p&gt;</description><pubDate>Thu, 27 Sep 2007 18:11:00 GMT</pubDate><guid isPermaLink="true">https://weblogs.asp.net:443/bradvincent/lets-play-catchup-bigtime</guid><category>random</category></item></channel></rss>