<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/rss2full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" version="2.0">
    <channel>
        <title>Rydal's .Net Clr </title>
        <link>http://blog.dotnetclr.com/Default.aspx</link>
        <description>Reality is just a shared illusion.</description>
        <language>en-US</language>
        <copyright>Rydal Williams</copyright>
        <generator>Subtext Version 2.1.0.5</generator>
        <image>
            <title>Rydal's .Net Clr </title>
            <url>http://blog.dotnetclr.com/images/RSS2Image.gif</url>
            <link>http://blog.dotnetclr.com/Default.aspx</link>
            <width>77</width>
            <height>60</height>
        </image>
        <atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="self" href="http://feeds.feedburner.com/dotnetclr" type="application/rss+xml" /><feedburner:emailServiceId>dotnetclr</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><item>
            <title>Concatenating multiple rows into single column in SQL Server</title>
            <category>MS SQL Server 2005</category>
            <category>MS SQL Server 2008</category>
            <category>MS Sql Server </category>
            <link>http://feedproxy.google.com/~r/dotnetclr/~3/M4L7pdFIFig/512.aspx</link>
            <description>&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/374BP0rP5NhwbrHvp4KY9qxEJuY/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/374BP0rP5NhwbrHvp4KY9qxEJuY/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/374BP0rP5NhwbrHvp4KY9qxEJuY/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/374BP0rP5NhwbrHvp4KY9qxEJuY/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Sometimes you need to return a single column that contains values that are comma separated or pipe separated or what ever floats your boat from a multiple row result set, a perfect example is returning the category id’s for a product that could be in one of more categories but you don’t want to return multiple rows with duplicate information.&lt;/p&gt;  &lt;p&gt;There are two ways of doing this or two that I know of – meaning simple enough.&lt;/p&gt;  &lt;p&gt;1. The &lt;strong&gt;COALESCE &lt;/strong&gt;method, which is probably the most common. This method works by tricking the coalesce function into doing something else, &lt;strong&gt;COALESCE &lt;/strong&gt;is very similar to &lt;strong&gt;ISNULL &lt;/strong&gt;except it can take in more than 2 arguments.&lt;/p&gt;  &lt;div&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;select&lt;/span&gt; @results = &lt;span class="kwrd"&gt;COALESCE&lt;/span&gt;(&lt;span class="kwrd"&gt;cast&lt;/span&gt;(ProductCategoryId &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;)+&lt;span class="str"&gt;','&lt;/span&gt;,&lt;span class="str"&gt;''&lt;/span&gt;)
    &lt;span class="kwrd"&gt;from&lt;/span&gt; ProductCategory &lt;span class="kwrd"&gt;where&lt;/span&gt; ProductId = 24&lt;/pre&gt;
&lt;/div&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;2. Using the &lt;strong&gt;FOR XML PATH&lt;/strong&gt; expression which works very well and its probably my preferred method because it takes order into consideration. If you use the &lt;strong&gt;FOR XML PATH&lt;/strong&gt; without specifying the column name, you get concatenation – cool trick huh?&lt;/p&gt;

&lt;div&gt;
  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;select&lt;/span&gt; &lt;span class="kwrd"&gt;cast&lt;/span&gt;(ProductCategoryId &lt;span class="kwrd"&gt;as&lt;/span&gt; &lt;span class="kwrd"&gt;varchar&lt;/span&gt;) + &lt;span class="str"&gt;','&lt;/span&gt; &lt;span class="kwrd"&gt;from&lt;/span&gt; Productcategory
            &lt;span class="kwrd"&gt;where&lt;/span&gt; ProductId = 24 &lt;span class="kwrd"&gt;for&lt;/span&gt; xml &lt;span class="kwrd"&gt;path&lt;/span&gt;(&lt;span class="str"&gt;''&lt;/span&gt;)&lt;/pre&gt;
&lt;/div&gt;

&lt;p /&gt;

&lt;p&gt;Have fun!!!&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blog.dotnetclr.com/archive/2009/09/29/512.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blog.dotnetclr.com/archive/2009/09/29/512.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blog.dotnetclr.com/aggbug/512.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetclr/~4/M4L7pdFIFig" height="1" width="1"/&gt;</description>
            <dc:creator>Rydal Williams</dc:creator>
            <guid isPermaLink="false">http://blog.dotnetclr.com/archive/2009/09/29/512.aspx</guid>
            <pubDate>Tue, 29 Sep 2009 19:44:04 GMT</pubDate>
            <wfw:comment>http://blog.dotnetclr.com/comments/512.aspx</wfw:comment>
            <comments>http://blog.dotnetclr.com/archive/2009/09/29/512.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blog.dotnetclr.com/comments/commentRss/512.aspx</wfw:commentRss>
            <trackback:ping>http://blog.dotnetclr.com/services/trackbacks/512.aspx</trackback:ping>
        <feedburner:origLink>http://blog.dotnetclr.com/archive/2009/09/29/512.aspx</feedburner:origLink></item>
        <item>
            <title>Using web.config for SMTP settings</title>
            <category>.Net</category>
            <category>C#</category>
            <category>Microsoft Visual Studio 2008</category>
            <link>http://feedproxy.google.com/~r/dotnetclr/~3/wBGehJlvCn8/511.aspx</link>
            <description>&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/WCyIkrJW1Sldubk2svu5OeCupZM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WCyIkrJW1Sldubk2svu5OeCupZM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/WCyIkrJW1Sldubk2svu5OeCupZM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/WCyIkrJW1Sldubk2svu5OeCupZM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;In the old days, we have to manually create custom configuration sections if we want to do cool stuff with app/web.config or simply just put the values in the appSettings section. However, there are a few config options that are out there that most developers don’t know about, a perfect example is the mailSettings config section which allows you to setup your mail settings in your configuration file and simply call the SMTPClient to send an email and by doing so, changing settings can be done on the fly and oh’ if you are worried about security, don’t forget you can definitely encrypt your configuration file if you need to.&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;system.net&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;mailSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;smtp&lt;/span&gt; &lt;span class="attr"&gt;deliveryMethod&lt;/span&gt;&lt;span class="kwrd"&gt;="Network"&lt;/span&gt; &lt;span class="attr"&gt;from&lt;/span&gt;&lt;span class="kwrd"&gt;="name@domain.com"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;network&lt;/span&gt; &lt;span class="attr"&gt;host&lt;/span&gt;&lt;span class="kwrd"&gt;="smtp.mail.com"&lt;/span&gt; 
                     &lt;span class="attr"&gt;userName&lt;/span&gt;&lt;span class="kwrd"&gt;="name@domain.com"&lt;/span&gt; 
                     &lt;span class="attr"&gt;password&lt;/span&gt;&lt;span class="kwrd"&gt;="blog.dotnetclr.com"&lt;/span&gt; &lt;span class="attr"&gt;port&lt;/span&gt;&lt;span class="kwrd"&gt;="25"&lt;/span&gt;&lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;smtp&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;mailSettings&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;system.net&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;And here is the sample C# code that will use the above configuration settings&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; SendBy(&lt;span class="kwrd"&gt;string&lt;/span&gt; to, &lt;span class="kwrd"&gt;string&lt;/span&gt; subject, &lt;span class="kwrd"&gt;string&lt;/span&gt; body)
{
    var mailMessage = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Net.Mail.MailMessage();
    mailMessage.To.Add(to);
    mailMessage.Subject = subject;
    mailMessage.Body = body;

    var smtpClient = &lt;span class="kwrd"&gt;new&lt;/span&gt; SmtpClient();
    smtpClient.EnableSsl = &lt;span class="kwrd"&gt;true&lt;/span&gt;;
    smtpClient.Send(mailMessage);
}&lt;/pre&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blog.dotnetclr.com/archive/2009/08/18/511.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blog.dotnetclr.com/archive/2009/08/18/511.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blog.dotnetclr.com/aggbug/511.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetclr/~4/wBGehJlvCn8" height="1" width="1"/&gt;</description>
            <dc:creator>Rydal Williams</dc:creator>
            <guid isPermaLink="false">http://blog.dotnetclr.com/archive/2009/08/18/511.aspx</guid>
            <pubDate>Wed, 19 Aug 2009 02:02:33 GMT</pubDate>
            <wfw:comment>http://blog.dotnetclr.com/comments/511.aspx</wfw:comment>
            <comments>http://blog.dotnetclr.com/archive/2009/08/18/511.aspx#feedback</comments>
            <wfw:commentRss>http://blog.dotnetclr.com/comments/commentRss/511.aspx</wfw:commentRss>
            <trackback:ping>http://blog.dotnetclr.com/services/trackbacks/511.aspx</trackback:ping>
        <feedburner:origLink>http://blog.dotnetclr.com/archive/2009/08/18/511.aspx</feedburner:origLink></item>
        <item>
            <title>Refresh SQL Server 2008 Intellisense</title>
            <link>http://feedproxy.google.com/~r/dotnetclr/~3/7h7ywtQSAgs/510.aspx</link>
            <description>&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/lXV_sliExalP8OpNcUgygd1Q0aE/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lXV_sliExalP8OpNcUgygd1Q0aE/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/lXV_sliExalP8OpNcUgygd1Q0aE/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/lXV_sliExalP8OpNcUgygd1Q0aE/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;If you are are using Microsoft SQL Server 2008 Management Studio, you would have noticed that it does have intellisense built in and very addictive if I must add. Anyway, problem here is SQL Server caches schema’s, therefore, when you make a schema change such as adding a new column to a table, intellisense doesn’t pick it up immediate. To quickly refresh the cache strike (&lt;strong&gt;CTRL+Shift+R&lt;/strong&gt;) and that should do it. Viola!&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blog.dotnetclr.com/archive/2009/08/14/510.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blog.dotnetclr.com/archive/2009/08/14/510.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blog.dotnetclr.com/aggbug/510.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetclr/~4/7h7ywtQSAgs" height="1" width="1"/&gt;</description>
            <dc:creator>Rydal Williams</dc:creator>
            <guid isPermaLink="false">http://blog.dotnetclr.com/archive/2009/08/14/510.aspx</guid>
            <pubDate>Fri, 14 Aug 2009 15:58:34 GMT</pubDate>
            <wfw:comment>http://blog.dotnetclr.com/comments/510.aspx</wfw:comment>
            <comments>http://blog.dotnetclr.com/archive/2009/08/14/510.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://blog.dotnetclr.com/comments/commentRss/510.aspx</wfw:commentRss>
            <trackback:ping>http://blog.dotnetclr.com/services/trackbacks/510.aspx</trackback:ping>
        <feedburner:origLink>http://blog.dotnetclr.com/archive/2009/08/14/510.aspx</feedburner:origLink></item>
        <item>
            <title>A simple way to resize an image</title>
            <category>.Net</category>
            <category>.Net Framework 2.0</category>
            <category>.Net Framework 3.0</category>
            <category>.Net Framework 3.5</category>
            <category>C#</category>
            <category>C# 2.0</category>
            <category>C# 3.0</category>
            <category>General</category>
            <link>http://feedproxy.google.com/~r/dotnetclr/~3/zd0jJgxvKg0/509.aspx</link>
            <description>&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/8Nx4yHQSe2CZT7u9hv6V0pnULD0/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8Nx4yHQSe2CZT7u9hv6V0pnULD0/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/8Nx4yHQSe2CZT7u9hv6V0pnULD0/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/8Nx4yHQSe2CZT7u9hv6V0pnULD0/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Here is a very simple way to resize an image using a bitmap as a canvas and the graphics object as a the resizing tool. Don’t forget to reference System.Drawing.&lt;/p&gt;  &lt;div&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="rem"&gt;/// &amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// Resizes an image from a source file to a destination file&lt;/span&gt;
&lt;span class="rem"&gt;/// the destination file will contain the exact image at the size specified&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;param name="sourceImagePath"&amp;gt;the source image file that needs to be resized&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;param name="destinationImagePath"&amp;gt;the destination path that the source &lt;/span&gt;
&lt;span class="rem"&gt;/// image file needs to be resized to&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;param name="width"&amp;gt;the new width&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span class="rem"&gt;/// &amp;lt;param name="height"&amp;gt;the new height&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;span class="kwrd"&gt;static&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; ResizeImage(&lt;span class="kwrd"&gt;string&lt;/span&gt; sourceImagePath, 
    &lt;span class="kwrd"&gt;string&lt;/span&gt; destinationImagePath, &lt;span class="kwrd"&gt;int&lt;/span&gt; width, &lt;span class="kwrd"&gt;int&lt;/span&gt; height)
{
    &lt;span class="rem"&gt;// Create an image object of the original image&lt;/span&gt;
    System.Drawing.Image 
        originalImage = System.Drawing.Image.FromFile(sourceImagePath, &lt;span class="kwrd"&gt;true&lt;/span&gt;);     

    &lt;span class="rem"&gt;// Create a new bitmap that we will use as a canvas to drawn on the new resized imaged&lt;/span&gt;
    Bitmap newBitmap = &lt;span class="kwrd"&gt;new&lt;/span&gt; Bitmap(originalImage, &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Drawing.Size(width, height));

    &lt;span class="rem"&gt;// Using the graphics object draw the orginal image on the canvas that was created above&lt;/span&gt;
    &lt;span class="kwrd"&gt;using&lt;/span&gt; (Graphics g = Graphics.FromImage(newBitmap))
    {
        g.InterpolationMode = 
            System.Drawing.Drawing2D.InterpolationMode.HighQualityBicubic;
        g.DrawImage(originalImage, 0, 0, width, height);
    }

    &lt;span class="rem"&gt;// Save the new resize image to a new path&lt;/span&gt;
    ((Image)newBitmap).Save(destinationImagePath);
}&lt;/pre&gt;
&lt;/div&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blog.dotnetclr.com/archive/2009/07/28/509.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blog.dotnetclr.com/archive/2009/07/28/509.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blog.dotnetclr.com/aggbug/509.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetclr/~4/zd0jJgxvKg0" height="1" width="1"/&gt;</description>
            <dc:creator>Rydal Williams</dc:creator>
            <guid isPermaLink="false">http://blog.dotnetclr.com/archive/2009/07/28/509.aspx</guid>
            <pubDate>Tue, 28 Jul 2009 14:13:14 GMT</pubDate>
            <wfw:comment>http://blog.dotnetclr.com/comments/509.aspx</wfw:comment>
            <comments>http://blog.dotnetclr.com/archive/2009/07/28/509.aspx#feedback</comments>
            <wfw:commentRss>http://blog.dotnetclr.com/comments/commentRss/509.aspx</wfw:commentRss>
            <trackback:ping>http://blog.dotnetclr.com/services/trackbacks/509.aspx</trackback:ping>
        <feedburner:origLink>http://blog.dotnetclr.com/archive/2009/07/28/509.aspx</feedburner:origLink></item>
        <item>
            <title>Write out page load times using an HttpModule and the stopwatch class</title>
            <category>ASP.NET 2.0</category>
            <category>ASP.NET</category>
            <category>.Net</category>
            <category>.Net Framework 2.0</category>
            <category>.Net Framework 3.0</category>
            <category>.Net Framework 3.5</category>
            <category>C#</category>
            <category>C# 2.0</category>
            <category>C# 3.0</category>
            <category>General</category>
            <link>http://feedproxy.google.com/~r/dotnetclr/~3/dZDllSmkUBQ/508.aspx</link>
            <description>&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/kcFgQosw4jYkmKeGtU_GKg27MN4/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kcFgQosw4jYkmKeGtU_GKg27MN4/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/kcFgQosw4jYkmKeGtU_GKg27MN4/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/kcFgQosw4jYkmKeGtU_GKg27MN4/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;One of the most efficient and non-intrusive ways you can implement an intercepting procedure is via an HttpModule. An HttpModule simply receives every request going to or coming from IIS and it allows you to manipulate the content as you see fit and pass it along. I wanted to spit out the time it takes from receiving a request to writing the response on one or more web pages and there was no other better way of doing it except writing an HttpModule, it toke me all but 10mins. Here is the code, feel free to blow it up.&lt;/p&gt;  &lt;div&gt;   &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;class&lt;/span&gt; PageLoadTime: System.Web.IHttpModule
{
    &lt;span class="preproc"&gt;#region&lt;/span&gt; IHttpModule Members

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Dispose()
    {
        &lt;span class="rem"&gt;// nothing to dispose off&lt;/span&gt;
    }

    &lt;span class="kwrd"&gt;public&lt;/span&gt; &lt;span class="kwrd"&gt;void&lt;/span&gt; Init(System.Web.HttpApplication context)
    {
        context.BeginRequest += &lt;span class="kwrd"&gt;new&lt;/span&gt; EventHandler(context_BeginRequest);
        context.EndRequest += &lt;span class="kwrd"&gt;new&lt;/span&gt; EventHandler(context_EndRequest);
    }

    &lt;span class="kwrd"&gt;bool&lt;/span&gt; IsReady(System.Web.HttpContext ctx)
    {
        &lt;span class="kwrd"&gt;return&lt;/span&gt; (ctx.IsDebuggingEnabled 
            &amp;amp;&amp;amp; ctx.Request.IsLocal 
            &amp;amp;&amp;amp; ctx.Response.ContentType.Equals(&lt;span class="str"&gt;"text/html"&lt;/span&gt;));
    }

    &lt;span class="kwrd"&gt;void&lt;/span&gt; context_BeginRequest(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (IsReady(HttpContext.Current))
        {
            Stopwatch sw = &lt;span class="kwrd"&gt;new&lt;/span&gt; Stopwatch();
            HttpContext.Current.Items.Add(&lt;span class="str"&gt;"PageLoadTimeStopWatch"&lt;/span&gt;, sw);
            sw.Start();
        }
    }

    &lt;span class="kwrd"&gt;void&lt;/span&gt; context_EndRequest(&lt;span class="kwrd"&gt;object&lt;/span&gt; sender, EventArgs e)
    {
        &lt;span class="kwrd"&gt;if&lt;/span&gt; (IsReady(HttpContext.Current))
        {
            &lt;span class="rem"&gt;// stop the watch&lt;/span&gt;
            Stopwatch sw = (Stopwatch)HttpContext.Current.Items[&lt;span class="str"&gt;"PageLoadTimeStopWatch"&lt;/span&gt;];
            sw.Stop();

            &lt;span class="rem"&gt;// render the time elapsed&lt;/span&gt;
            &lt;span class="kwrd"&gt;string&lt;/span&gt; elapsedTime = &lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(
                &lt;span class="str"&gt;"&amp;lt;b&amp;gt;Page Loaded In &amp;lt;font color=red&amp;gt;{0}&amp;lt;/font&amp;gt; secs&amp;lt;/b&amp;gt;"&lt;/span&gt;, 
                &lt;span class="kwrd"&gt;decimal&lt;/span&gt;.Round(&lt;span class="kwrd"&gt;decimal&lt;/span&gt;.Parse(sw.Elapsed.TotalSeconds.ToString()), 2));
            HttpContext.Current.Response.Write(&lt;span class="kwrd"&gt;string&lt;/span&gt;.Format(&lt;span class="str"&gt;"{0}"&lt;/span&gt;, elapsedTime));
        }
    }

    &lt;span class="preproc"&gt;#endregion&lt;/span&gt;
}&lt;/pre&gt;
&lt;/div&gt;
&lt;span class="sbmLink"&gt;
  &lt;table cellspacing="1" cellpadding="1"&gt;&lt;tbody&gt;
      &lt;tr&gt;
        &lt;td class="sbmText"&gt;Share this post : &lt;/td&gt;

        &lt;td&gt;&lt;a title="Post it to MSDN!" href="http://social.msdn.microsoft.com/en-us/action/create/s/E/?url=http://blog.dotnetclr.com/archive/2009/07/24/508.aspx&amp;amp;ttl=Write out page load times using an HttpModule and the stopwatch class" target="_blank"&gt;&lt;img src="http://www.dotnetscraps.com/dotnetscraps/samples/sbmtool/msdn.png" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;

        &lt;td&gt;&lt;a title="Post it to del.icio.us" href="http://del.icio.us/post?url=http://blog.dotnetclr.com/archive/2009/07/24/508.aspx&amp;amp;;title=Write out page load times using an HttpModule and the stopwatch class" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/deliciou4.png" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;

        &lt;td&gt;&lt;a title="Post it to digg" href="http://digg.com/submit?phase=2&amp;amp;url=http://blog.dotnetclr.com/archive/2009/07/24/508.aspx&amp;amp;title=Write out page load times using an HttpModule and the stopwatch class" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/digg14.png" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;

        &lt;td&gt;&lt;a title="Post it to dotnetkicks" href="http://www.dotnetkicks.com/kick/?url=http://blog.dotnetclr.com/archive/2009/07/24/508.aspx&amp;amp;title=Write out page load times using an HttpModule and the stopwatch class" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/CropperCapture154.jpg" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;

        &lt;td&gt;&lt;a title="Post it to Facebook" href="http://www.facebook.com/sharer.php?u=http://blog.dotnetclr.com/archive/2009/07/24/508.aspx&amp;amp;t=Write out page load times using an HttpModule and the stopwatch class" target="_blank"&gt;&lt;img src="http://blogs.technet.com/photos/james/images/1765319/original.aspx" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;

        &lt;td&gt;&lt;a title="Post it to furl" href="http://www.furl.net/store?s=f&amp;amp;to=0&amp;amp;u=http://blog.dotnetclr.com/archive/2009/07/24/508.aspx&amp;amp;ti=Write out page load times using an HttpModule and the stopwatch class" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/furl4.png" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;

        &lt;td&gt;&lt;a title="Post it to live" href="https://favorites.live.com/quickadd.aspx?marklet=1&amp;amp;mkt=en-us&amp;amp;url=http://blog.dotnetclr.com/archive/2009/07/24/508.aspx&amp;amp;title=Write out page load times using an HttpModule and the stopwatch class" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/live4.png" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;

        &lt;td&gt;&lt;a title="Post it to magnolia!" href="http://ma.gnolia.com/bookmarklet/add?url=http://blog.dotnetclr.com/archive/2009/07/24/508.aspx&amp;amp;title=Write out page load times using an HttpModule and the stopwatch class" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/magnolia4.png" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;

        &lt;td&gt;&lt;a title="Post it to reddit!" href="http://reddit.com/submit?url=http://blog.dotnetclr.com/archive/2009/07/24/508.aspx&amp;amp;title=Write out page load times using an HttpModule and the stopwatch class" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/reddit4.png" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;

        &lt;td&gt;&lt;a title="Post it to technorati!" href="http://technorati.com/faves/?add=http://blog.dotnetclr.com/archive/2009/07/24/508.aspx&amp;amp;title=Write out page load times using an HttpModule and the stopwatch class" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/technora4.png" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;

        &lt;td&gt;&lt;a title="Post it to yahoo!" href="http://myweb.yahoo.com/myresults/bookmarklet?u=http://blog.dotnetclr.com/archive/2009/07/24/508.aspx&amp;amp;t=Write out page load times using an HttpModule and the stopwatch class" target="_blank"&gt;&lt;img src="http://blogs.msdn.com/blogfiles/rahulso/WindowsLiveWriter/IconsfordifferentSocialBookmarkingSites_B387/yahoo9.png" border="0" /&gt;&lt;/a&gt;&lt;/td&gt;
      &lt;/tr&gt;
    &lt;/tbody&gt;&lt;/table&gt;
&lt;/span&gt;&lt;img src="http://blog.dotnetclr.com/aggbug/508.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetclr/~4/dZDllSmkUBQ" height="1" width="1"/&gt;</description>
            <dc:creator>Rydal Williams</dc:creator>
            <guid isPermaLink="false">http://blog.dotnetclr.com/archive/2009/07/24/508.aspx</guid>
            <pubDate>Fri, 24 Jul 2009 17:40:21 GMT</pubDate>
            <wfw:comment>http://blog.dotnetclr.com/comments/508.aspx</wfw:comment>
            <comments>http://blog.dotnetclr.com/archive/2009/07/24/508.aspx#feedback</comments>
            <wfw:commentRss>http://blog.dotnetclr.com/comments/commentRss/508.aspx</wfw:commentRss>
            <trackback:ping>http://blog.dotnetclr.com/services/trackbacks/508.aspx</trackback:ping>
        <feedburner:origLink>http://blog.dotnetclr.com/archive/2009/07/24/508.aspx</feedburner:origLink></item>
        <item>
            <title>MySpace&amp;rsquo;s Performance Tracker</title>
            <category>General</category>
            <link>http://feedproxy.google.com/~r/dotnetclr/~3/7BOQJK6o4Qo/507.aspx</link>
            <description>&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/p6WSmia6MSsIVLfhPvG-lx9Y6tM/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/p6WSmia6MSsIVLfhPvG-lx9Y6tM/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/p6WSmia6MSsIVLfhPvG-lx9Y6tM/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/p6WSmia6MSsIVLfhPvG-lx9Y6tM/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;It seems the &lt;strong&gt;MySpace&lt;/strong&gt; gurus are giving back to the community, they are now providing there IE performance tracker for free to the public.&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;MySpace’s Performance Tracker is a browser plug-in that help developers to improve their code performance by capturing and measuring possible bottlenecks on their web pages.&lt;/p&gt; &lt;/blockquote&gt;  &lt;ul&gt;   &lt;li&gt;Measure the CPU hit and memory footprint of your pages as they render on the client’s browser &lt;/li&gt;    &lt;li&gt;Review screen shots of the page while it renders &lt;/li&gt;    &lt;li&gt;Review the rendered HTML on each point of the page’s lifecycle &lt;/li&gt;    &lt;li&gt;Measure and show estimates of the time it takes to render each section of the page in different connection speeds &lt;/li&gt;    &lt;li&gt;Validate the content of your page against a set of proven “best practice” rules of web development &lt;/li&gt;    &lt;li&gt;Review downloaded files and show download time estimation on different bandwidths &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;MySpace’s Performance Tracker currently supports &lt;strong&gt;Internet Explorer 6 and up&lt;/strong&gt;.&lt;/p&gt;  &lt;p&gt;&lt;a href="http://msfast.myspace.com/"&gt;Download here&lt;/a&gt;&lt;/p&gt;  &lt;p&gt; &lt;/p&gt;  &lt;p&gt;&lt;a href="http://blog.dotnetclr.com/images/blog_dotnetclr_com/WindowsLiveWriter/MySpacesPerformanceTracker_1108A/image_2.png"&gt;&lt;img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://blog.dotnetclr.com/images/blog_dotnetclr_com/WindowsLiveWriter/MySpacesPerformanceTracker_1108A/image_thumb.png" width="240" height="108" /&gt;&lt;/a&gt;&lt;/p&gt;&lt;div class="wlWriterHeaderFooter" style="text-align:left; margin:0px; padding:4px 4px 4px 4px;"&gt;&lt;a href="http://www.dotnetkicks.com/kick/?url=http://blog.dotnetclr.com/archive/2009/07/01/507.aspx"&gt;&lt;img src="http://www.dotnetkicks.com/Services/Images/KickItImageGenerator.ashx?url=http://blog.dotnetclr.com/archive/2009/07/01/507.aspx&amp;amp;bgcolor=0080C0&amp;amp;fgcolor=FFFFFF&amp;amp;border=000000&amp;amp;cbgcolor=D4E1ED&amp;amp;cfgcolor=000000" alt="DotNetKicks Image" border="0/" /&gt;&lt;/a&gt;&lt;/div&gt;&lt;img src="http://blog.dotnetclr.com/aggbug/507.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetclr/~4/7BOQJK6o4Qo" height="1" width="1"/&gt;</description>
            <dc:creator>Rydal Williams</dc:creator>
            <guid isPermaLink="false">http://blog.dotnetclr.com/archive/2009/07/01/507.aspx</guid>
            <pubDate>Wed, 01 Jul 2009 23:23:41 GMT</pubDate>
            <wfw:comment>http://blog.dotnetclr.com/comments/507.aspx</wfw:comment>
            <comments>http://blog.dotnetclr.com/archive/2009/07/01/507.aspx#feedback</comments>
            <wfw:commentRss>http://blog.dotnetclr.com/comments/commentRss/507.aspx</wfw:commentRss>
            <trackback:ping>http://blog.dotnetclr.com/services/trackbacks/507.aspx</trackback:ping>
        <feedburner:origLink>http://blog.dotnetclr.com/archive/2009/07/01/507.aspx</feedburner:origLink></item>
        <item>
            <title>Convert virtual path to absolute or relative path</title>
            <link>http://feedproxy.google.com/~r/dotnetclr/~3/-DldpWkOk2E/506.aspx</link>
            <description>&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/Si3pU9bLP3RohNNsz6T4JWS0kbU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Si3pU9bLP3RohNNsz6T4JWS0kbU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/Si3pU9bLP3RohNNsz6T4JWS0kbU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/Si3pU9bLP3RohNNsz6T4JWS0kbU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;There are a lot of goodies embedded in the framework, problem is, there are so many namespaces that it is almost impossible to know them all, as a matter of fact I doubt that there is any one person that knows all of the framework in and out. As usual, this post is about my experience with weird code that could have been done easily using existing built functions. I’ve seen developers write 20+ lines of code to this stuff while covering every possible scenario.&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;u&gt;convert to absolute&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;  &lt;div&gt;   &lt;div class="csharpcode"&gt;     &lt;pre class="alt"&gt;System.Web.VirtualPathUtility.ToAbsolute(&lt;span class="kwrd"&gt;params&lt;/span&gt;);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;u&gt;convert to relative&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;div&gt;
  &lt;div class="csharpcode"&gt;
    &lt;pre class="alt"&gt;System.Web.VirtualPathUtility.ToAppRelative(&lt;span class="kwrd"&gt;params&lt;/span&gt;);&lt;/pre&gt;

    &lt;pre class="alteven"&gt;System.Web.VirtualPathUtility.MakeRelative(&lt;span class="kwrd"&gt;params&lt;/span&gt;);&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;&lt;img src="http://blog.dotnetclr.com/aggbug/506.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetclr/~4/-DldpWkOk2E" height="1" width="1"/&gt;</description>
            <dc:creator>Rydal Williams</dc:creator>
            <guid isPermaLink="false">http://blog.dotnetclr.com/archive/2009/06/08/506.aspx</guid>
            <pubDate>Mon, 08 Jun 2009 21:43:49 GMT</pubDate>
            <wfw:comment>http://blog.dotnetclr.com/comments/506.aspx</wfw:comment>
            <comments>http://blog.dotnetclr.com/archive/2009/06/08/506.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://blog.dotnetclr.com/comments/commentRss/506.aspx</wfw:commentRss>
            <trackback:ping>http://blog.dotnetclr.com/services/trackbacks/506.aspx</trackback:ping>
        <feedburner:origLink>http://blog.dotnetclr.com/archive/2009/06/08/506.aspx</feedburner:origLink></item>
        <item>
            <title>Converting SQL DateTime to Date</title>
            <link>http://feedproxy.google.com/~r/dotnetclr/~3/pEfQtaOqFf0/505.aspx</link>
            <description>&lt;p&gt;&lt;a href="http://feedads.g.doubleclick.net/~a/-pRL5VkANATErG_5UUWYrwJsvLU/0/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-pRL5VkANATErG_5UUWYrwJsvLU/0/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;br/&gt;
&lt;a href="http://feedads.g.doubleclick.net/~a/-pRL5VkANATErG_5UUWYrwJsvLU/1/da"&gt;&lt;img src="http://feedads.g.doubleclick.net/~a/-pRL5VkANATErG_5UUWYrwJsvLU/1/di" border="0" ismap="true"&gt;&lt;/img&gt;&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Apparently, converting a SQL long &lt;strong&gt;datetime&lt;/strong&gt; string to just a date seems to be a head banger for some people. therefore, I’ve decided to publish the way I do it, which I believe is easy and probably the most efficient.&lt;/p&gt;  &lt;div&gt;   &lt;div class="csharpcode"&gt;     &lt;pre class="alt"&gt;&lt;span class="kwrd"&gt;convert&lt;/span&gt;(&lt;span class="kwrd"&gt;varchar&lt;/span&gt;(10),[datetimecolumnname],101)&lt;/pre&gt;
  &lt;/div&gt;
&lt;/div&gt;

&lt;p&gt; &lt;/p&gt;

&lt;p&gt;replace &lt;strong&gt;[datetimecolumnname]&lt;/strong&gt; with the column name of the actual column that is of &lt;strong&gt;datetime&lt;/strong&gt; data type.&lt;/p&gt;&lt;img src="http://blog.dotnetclr.com/aggbug/505.aspx" width="1" height="1" /&gt;&lt;img src="http://feeds.feedburner.com/~r/dotnetclr/~4/pEfQtaOqFf0" height="1" width="1"/&gt;</description>
            <dc:creator>Rydal Williams</dc:creator>
            <guid isPermaLink="false">http://blog.dotnetclr.com/archive/2009/06/08/505.aspx</guid>
            <pubDate>Mon, 08 Jun 2009 15:09:11 GMT</pubDate>
            <wfw:comment>http://blog.dotnetclr.com/comments/505.aspx</wfw:comment>
            <comments>http://blog.dotnetclr.com/archive/2009/06/08/505.aspx#feedback</comments>
            <wfw:commentRss>http://blog.dotnetclr.com/comments/commentRss/505.aspx</wfw:commentRss>
            <trackback:ping>http://blog.dotnetclr.com/services/trackbacks/505.aspx</trackback:ping>
        <feedburner:origLink>http://blog.dotnetclr.com/archive/2009/06/08/505.aspx</feedburner:origLink></item>
    </channel>
</rss>
