<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://samuraiprogrammer.com/community/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Samurai Programmer.com</title><link>http://samuraiprogrammer.com/community/blogs/greg/default.aspx</link><description>"I know Kung-Fu..."</description><dc:language>en</dc:language><generator>CommunityServer 2.1 (Build: 60804.900)</generator><item><title>How to reset your Flip UltraHD Video camcorder</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2010/03/13/How-to-reset-your-Flip-UltraHD-Video-camcorder.aspx</link><pubDate>Sat, 13 Mar 2010 17:15:16 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:614</guid><dc:creator>Greg</dc:creator><slash:comments>0</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/614.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=614</wfw:commentRss><description>&lt;p&gt;I recently ran into a problem with my &lt;a href="http://store.theflip.com/en-us/products/UltraHD.aspx" target="_blank"&gt;Flip UltraHD Video camcorder&lt;/a&gt; where it would not turn on.&amp;#160; Unlike other camcorders in the Flip family, there is no microscopic reset button anywhere on the device.&lt;/p&gt;  &lt;p&gt;After e-mailing support, I received a response the next day with the steps to reset the device.&amp;#160; For some reason, this information is not listed in their knowledge base on the &lt;a href="http://www.theflip.com/en-us/support/" target="_blank"&gt;support site&lt;/a&gt;, so I thought I would post it here.&amp;#160; &lt;/p&gt;  &lt;p&gt;The steps to reset/resolve an issue where your UltraHD will not turn on is as follows:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Remove the battery pack from the camcorder.&lt;/li&gt;    &lt;li&gt;Connect the camcorder to a powered USB port on your computer.&lt;/li&gt;    &lt;li&gt;When the &amp;quot;Connected&amp;quot; indicator comes on, insert the battery pack into the camcorder.&lt;/li&gt;    &lt;li&gt;Safe eject your camcorder from your computer.&lt;/li&gt;    &lt;li&gt;Reconnect your camcorder to your computer.&lt;/li&gt;    &lt;li&gt;The battery pack should now begin to charge within the camcorder&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Hope this helps someone else out there.&amp;#160; &lt;/p&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=614" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Life/default.aspx">Life</category></item><item><title>Creating an instructor guide from a PowerPoint deck.</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2009/12/23/Creating-an-instructor-guide-from-a-PowerPoint-deck_2E00_.aspx</link><pubDate>Wed, 23 Dec 2009 08:45:16 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:590</guid><dc:creator>Greg</dc:creator><slash:comments>1</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/590.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=590</wfw:commentRss><description>&lt;p&gt;I recently came across the situation where I had several PowerPoint decks that were VERY well documented.&amp;#160; Essentially, each slide had reams of notes in the Notes panel of the deck.&amp;#160; This is both good and bad.&amp;#160; It was good because for preparation purposes, it was very easy to review the notes as you reviewed the slides.&amp;#160; It was bad because on many machines where I presented from, you could not split the monitors so the slides were on one machine and the notes were on another.&lt;/p&gt;  &lt;p&gt;This presented a conundrum because it’s nice to be able to have the notes handy as I present the material.&amp;#160; That way, I can refer back to the main bullets to make sure I covered everything before moving on.&amp;#160; For other workshops I teach, we have an instructor guide on paper that you can have up next to your presenter machine on the podium and all is good to go.&lt;/p&gt;  &lt;p&gt;Unfortunately, there was nothing like that setup already for this workshop.&amp;#160; Fortunately, PowerPoint 2007 provides a feature to export your presentation to Word 2007.&amp;#160; Full steps are located &lt;a href="http://office.microsoft.com/en-us/powerpoint/HA102252621033.aspx" target="_blank"&gt;here&lt;/a&gt; but essentially you are looking for this screen:&lt;/p&gt;  &lt;p&gt;&lt;img style="display:block;float:none;margin-left:auto;margin-right:auto;" border="0" alt="Creating handouts in Word" src="http://office.microsoft.com/global/images/default.aspx?AssetID=ZA102253551033" /&gt;&lt;/p&gt;  &lt;p&gt;This is a nice solution but the main problem that I had is that it embeds PowerPoint objects into the slide deck.&amp;#160; This *sounds* like a good idea but it grows the file size of the document to a huge degree.&amp;#160; For example, one deck had 36 slides and the file size of the resulting Word document was &amp;gt;50MB!&amp;#160; &lt;/p&gt;  &lt;p&gt;Fortunately, with some nice VBA code, you can do the following:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;Iterate through every shape in the document. &lt;/li&gt;    &lt;li&gt;Copy the PowerPoint object. &lt;/li&gt;    &lt;li&gt;Paste that object as a JPEG. &lt;/li&gt;    &lt;li&gt;Delete the PowerPoint object. &lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;That brings the file size back down to where it should be, from my perspective.&amp;#160; For example, in that file I mentioned previously, it brought the size down from 55MB to 642KB.&amp;#160; Talk about a tremendous improvement!&amp;#160; &lt;/p&gt;  &lt;p&gt;The VBA code to use is as follows:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;Sub ConvertPowerPointToImage()
    
    Dim j As InlineShape
    
    For Each j In Word.ActiveDocument.InlineShapes
        
        j.Select

        Selection.Copy

        Selection.PasteSpecial Link:=False, _
                  DataType:=15, 
                  Placement:=wdInLine, 
                  DisplayAsIcon:=False

        j.Delete
        
    Next j
    
    
End Sub&lt;/pre&gt;

&lt;p&gt;Just copy/paste the above code into a new module.&amp;#160; Then execute the “ConvertPowerPointToImage” macro.&amp;#160; That will clean everything up and make the file a lot more manageable.&amp;#160; &lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=590" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/VBA/default.aspx">VBA</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Office/default.aspx">Office</category></item><item><title>XmlDataSource and HTTP 401.2 Errors</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2009/09/04/XmlDataSource-and-HTTP-401.2-Errors.aspx</link><pubDate>Fri, 04 Sep 2009 19:21:28 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:585</guid><dc:creator>Greg</dc:creator><slash:comments>1</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/585.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=585</wfw:commentRss><description>&lt;p&gt;I was talking to a co-worker last weekend and he was troubleshooting a seemingly very simple issue with an XmlDataSource and an ASP.NET Menu control.&amp;#160; Essentially, his customer had an XML file that they wanted to use as a data source for the menu control.&amp;#160; It looked something like this:&lt;/p&gt;  &lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;?&lt;/span&gt;&lt;span class="html"&gt;xml&lt;/span&gt; &lt;span class="attr"&gt;version&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;1.0&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;encoding&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;utf-8&amp;quot;&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;root&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;menuitem&lt;/span&gt; &lt;span class="attr"&gt;url&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://www.bing.com&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Bing!&amp;quot;&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;menuitem&lt;/span&gt; &lt;span class="attr"&gt;url&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://www.live.com&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;text&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Live!&amp;quot;&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;root&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;The XHTML on their ASP.NET page was something like the following:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Menu&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;Menu1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;DataSourceID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;XmlDataSource1&amp;quot;&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;DataBindings&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;asp:MenuItemBinding&lt;/span&gt; &lt;span class="attr"&gt;DataMember&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;menuitem&amp;quot;&lt;/span&gt; 
                                     &lt;span class="attr"&gt;NavigateUrlField&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;url&amp;quot;&lt;/span&gt; 
                                     &lt;span class="attr"&gt;TextField&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;text&amp;quot;&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;DataBindings&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;asp:Menu&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;asp:XmlDataSource&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;XmlDataSource2&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; 
        &lt;span class="attr"&gt;DataFile&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http://localhost/MenuSample/SampleXMLFile.xml&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;Can you spot the potential problem here?&amp;#160; Well, when they ran the above code and got this error:&lt;/p&gt;

&lt;p&gt;&lt;a href="http://samuraiprogrammer.com/community/blogimages/XmlDataSourceandHTTP401.2Errors_13BEA/Error.png"&gt;&lt;img style="border-right-width:0px;display:inline;border-top-width:0px;border-bottom-width:0px;border-left-width:0px;" title="Error" border="0" alt="Error" src="http://samuraiprogrammer.com/community/blogimages/XmlDataSourceandHTTP401.2Errors_13BEA/Error_thumb.png" width="462" height="392" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;Now, one thing we found out was that their simple page (and XML File):&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:XmlDataSource&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;XmlDataSource2&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; 
        &lt;strong&gt;&lt;em&gt;&lt;span class="attr"&gt;DataFile&lt;/span&gt;&lt;span class="kwrd"&gt;&lt;font color="#ff0000"&gt;=&amp;quot;http://localhost/MenuSample/SampleXMLFile.xml&amp;quot;&lt;/font&gt;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;is being hosted in a VDir/Site protected with Windows Authentication.&amp;#160; In-fact, if we look at the IIS Logs, we see that the IIS is returning a 401.2 response:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;2009-09-03 05:33:47 ::1 GET /MenuSample/SampleXMLFile.xml - 80 - ::1 - &lt;strong&gt;&lt;font color="#ff0000"&gt;401 2&lt;/font&gt;&lt;/strong&gt; 5 1&lt;/pre&gt;

&lt;p&gt;After examining the call stack and the source code for the XmlDataSource, we see that in order to retrieve the XML file, we do something akin to the following:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;System.Xml.XmlDocument document = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Xml.XmlDocument();

System.Xml.XmlTextReader reader = &lt;span class="kwrd"&gt;new&lt;/span&gt; System.Xml.XmlTextReader(&lt;span class="str"&gt;&amp;quot;http://....&amp;quot;&lt;/span&gt;);

document.Load(reader);&lt;/pre&gt;

&lt;p&gt;The XmlDocument and XmlTextReader will eventually instantiate an XmlDownloadManager, which instantiates an HttpWebRequest – which is responsible for downloading the XML file.&amp;#160; At no point, though, are Credentials applied to this request, so the HTTP 401.2 response is returned from IIS.&amp;#160; &lt;/p&gt;

&lt;p&gt;Well, in this customer’s case – this was enough information for them and they moved the XML file to their local site and adjusted the DataFile attribute to a local file:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:XmlDataSource&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;XmlDataSource1&amp;quot;&lt;/span&gt; &lt;span class="attr"&gt;runat&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;server&amp;quot;&lt;/span&gt; 
        &lt;span class="attr"&gt;DataFile&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;~/SampleXMLFile.xml&amp;quot;&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;&lt;/pre&gt;

&lt;p&gt;So, for this customer – the problem was solved.&amp;#160; However, my mind started churning with ideas on how to solve this type of problem.&amp;#160; So, here is some ridiculous fun that I had solving the problem.&lt;/p&gt;

&lt;p&gt;First, a disclaimer:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;******************************************************** 
    &lt;br /&gt;&lt;strong&gt;These postings are provided as is with no warranties, and confers no rights. Additionally, views expressed herein are my own and not those of my employer, Microsoft. &lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;In addition, the following solution is intended to provide a sample of what can be done to solve this problem and is not an optimal solution for a number of reasons outlined below.&amp;#160; &lt;/strong&gt;&lt;/p&gt;

  &lt;p&gt;&lt;strong&gt;This is, simply put, some ridiculous fun that I had the other night bending the .NET framework to my will.&lt;/strong&gt; 

    &lt;br /&gt;********************************************************&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Okay, glad that’s out of the way.&amp;#160; So, how would you resolve this?&amp;#160; Unfortunately, the XmlDataSource does not have any extensibility points to add an authentication element to its xml file loading process.&amp;#160; So, there are really two things you can do:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Subclass the XmlDataSource and build-in that level of authentication. &lt;/li&gt;

  &lt;li&gt;Handle the Credentials piece when the HttpWebRequest gets created. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;I wrote both pieces but for this posting, I’ll only cover the second option because it uses an extensibility point that is not often utilized.&lt;/p&gt;

&lt;p&gt;So, in this instance, we would like to make sure that the HttpWebRequest that gets instantiated by the application always has the Credentials properties supplied to it.&amp;#160; Because we have no control over the code that consumes the HttpWebRequest – in this case the XmlDownloadManager class, if we want to control this, we need to go even further down.&amp;#160; &lt;/p&gt;

&lt;p&gt;So, ideally, when you call something like:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;System.Net.HttpWebRequest request = (System.Net.HttpWebRequest) 
      System.Net.WebRequest.Create(&lt;span class="str"&gt;&amp;quot;http://...&amp;quot;&lt;/span&gt;);&lt;/pre&gt;

&lt;p&gt;We would want to make sure that the System.Net.HttpWebRequest being returned from the Create(…) method has the Credentials property populated.&amp;#160; So, how would we do something like this?&lt;/p&gt;

&lt;p&gt;Well, the .NET Framework exposes a little known extensibility mechanism called &lt;a href="http://msdn.microsoft.com/en-us/library/bc0fhzk5.aspx" target="_blank"&gt;webRequestModules&lt;/a&gt;.&amp;#160; From the linked MSDN page, it states:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;“The webRequestModules element registers descendants of the &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.webrequest.aspx"&gt;WebRequest&lt;/a&gt; class to handle information requests to network hosts. Web request modules must implement the &lt;a href="http://msdn.microsoft.com/en-us/library/system.net.iwebrequestcreate.aspx"&gt;IWebRequestCreate&lt;/a&gt; interface.&lt;/p&gt;

  &lt;p&gt;The .NET Framework includes Web request modules for URIs that begin with http://, https://, and file://. You can override the default modules only by registering a custom module in the configuration file.”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;So, with this in-mind, we can create our own class that implements the IWebRequestCreate interface.&amp;#160; This class will just do the following:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Create an HttpWebRequest object. &lt;/li&gt;

  &lt;li&gt;Set the Credentials to the HttpWebRequest &lt;/li&gt;

  &lt;li&gt;Return the HttpWebRequest to its caller. &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;So, here’s the class to do exactly that:&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; CustomWebRequestCreator:System.Net.IWebRequestCreate
{

    &lt;span class="kwrd"&gt;public&lt;/span&gt; System.Net.WebRequest Create(Uri uri)
    {
        &lt;span class="rem"&gt;// Step 1 - Instantiate the HttpWebRequest.&lt;/span&gt;
        &lt;span class="rem"&gt;// We must use reflection since the constructor isn't public.&lt;/span&gt;
        Type t = &lt;span class="kwrd"&gt;typeof&lt;/span&gt;(System.Net.HttpWebRequest);

        &lt;span class="kwrd"&gt;object&lt;/span&gt;[] args = { uri, &lt;span class="kwrd"&gt;null&lt;/span&gt; };

        System.Reflection.ConstructorInfo[] cons = &lt;br /&gt;                      t.GetConstructors(
                          System.Reflection.BindingFlags.NonPublic |
                          System.Reflection.BindingFlags.Instance);

        System.Net.HttpWebRequest request = &lt;span class="kwrd"&gt;null&lt;/span&gt;;

        request = (System.Net.HttpWebRequest)cons[2].Invoke(args);

        &lt;span class="rem"&gt;// Step 2 - Set the Credentials property.&lt;/span&gt;
        request.Credentials = System.Net.CredentialCache.DefaultCredentials;

        &lt;span class="rem"&gt;// Step 3 - Return the object to its caller.&lt;/span&gt;
        &lt;span class="kwrd"&gt;return&lt;/span&gt; request;

    }

}&lt;/pre&gt;

&lt;p&gt;So, now that we have the code, we can compile it into an assembly and then add it to the webRequestModules section of the Web.Config:&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;webRequestModules&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;remove&lt;/span&gt; &lt;span class="attr"&gt;prefix&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http:&amp;quot;&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;add&lt;/span&gt; &lt;span class="attr"&gt;prefix&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;http:&amp;quot;&lt;/span&gt; 
           &lt;span class="attr"&gt;type&lt;/span&gt;&lt;span class="kwrd"&gt;=&amp;quot;WebRequests.CustomWebRequestCreator, WebRequests&amp;quot;&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;webRequestModules&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;The configuration element above removes the default .NET creator used for paths starting with “http:” and then substitutes ours in its place.&lt;/p&gt;

&lt;p&gt;So, now when you run the project with the above code, the requests logged in IIS are:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;2009-09-03 21:28:16 ::1 GET /MenuSample/SampleXMLFile.xml - 80 - &lt;font color="#ff0000"&gt;401 2&lt;/font&gt;
2009-09-03 21:28:16 ::1 GET /MenuSample/SampleXMLFile.xml - 80 - &lt;font color="#ff0000"&gt;200&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;The first request returns an authentication request and because we are setting the credentials of the HttpWebRequest, we can authenticate correctly and thus retrieve the Xml file.&lt;/p&gt;

&lt;p&gt;Now, there are a few things to keep in mind with this approach:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;This is a GLOBAL approach.&amp;#160; This means that ANY HTTP web request made by your application will go through this code.&amp;#160; So, caveat emptor.
    &lt;br /&gt;&lt;/li&gt;

  &lt;li&gt;This code uses reflection to instantiate the HttpWebRequest – which can have some performance implications.&amp;#160; You can do things to optimize this code-path but your mileage may vary.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Like I said above, this was just a bit of ridiculous fun on a Sunday night.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=585" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/ASP.NET+Tips+and+Tricks/default.aspx">ASP.NET Tips and Tricks</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/.NET/default.aspx">.NET</category></item><item><title>What’s new in .NET 4.0 SOS</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2009/08/28/What_1920_s-new-in-.NET-4.0-SOS.aspx</link><pubDate>Fri, 28 Aug 2009 15:15:20 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:584</guid><dc:creator>Greg</dc:creator><slash:comments>0</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/584.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=584</wfw:commentRss><description>&lt;p&gt;&lt;strong&gt;***************************************************&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;PLEASE NOTE – THIS POST IS BASED ON THE .NET 4.0 BETA THAT WAS MADE PUBLICLY AVAILABLE IN APRIL/MAY.&amp;#160; THIS INFORMATION IS SUBJECT TO CHANGE.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;***************************************************&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;So, anyone that I’ve worked with during my tenure knows that I have a big love affair with WinDBG and SOS.&amp;#160; In-fact, once you know how to use it, I’ve found that it’s my first choice in terms of debuggers – beating even Visual Studio.&amp;#160; So, when we released the first beta of .NET 4.0, I rushed to download it and see what’s available.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;Here are some new commands and new ways of doing things.&amp;#160; If you are not familiar with WinDBG and SOS, you can read a walkthrough &lt;a href="http://blogs.msdn.com/johan/archive/2007/11/13/getting-started-with-windbg-part-i.aspx" target="_blank"&gt;here&lt;/a&gt;.&lt;/font&gt;&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="3"&gt;Loading SOS:&lt;/font&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;Looks like mscorwks is gone and “clr.dll” is the new base assembly.&amp;#160; So to load SOS, the command you would use is: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p align="left"&gt;&lt;strong&gt;.loadby sos clr&lt;/strong&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Granted, you can still use: &lt;/p&gt;  &lt;blockquote&gt;   &lt;p align="left"&gt;&lt;strong&gt;.load c:\windows\microsoft.net\framework\vXXXXXX\sos.dll&lt;/strong&gt; &lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;But the “.loadby” command is shorter. &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;&lt;font size="3"&gt;Some New Commands:&lt;/font&gt;&lt;/strong&gt; &lt;/p&gt;  &lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;!ThreadState&lt;/strong&gt;&lt;/font&gt; &lt;/p&gt;  &lt;p&gt;In the !threads output, there was that “State” field: &lt;/p&gt;  &lt;pre class="csharpcode"&gt;0:000&amp;gt; !threads
…
       ID OSID ThreadOBJ    State     GC       Context       Domain   Count APT Exception
   0    1  820 0015e990      &lt;font color="#ff0000"&gt;&lt;strong&gt;a020&lt;/strong&gt;&lt;/font&gt; Enabled  00000000:00000000 00164ed8     0 MTA System.OutOfMemoryException (00d1deb8)
   2    2  244 0016fa88      &lt;font color="#ff0000"&gt;&lt;strong&gt;b220&lt;/strong&gt;&lt;/font&gt; Enabled  00000000:00000000 00164ed8     0 MTA (Finalizer)&lt;/pre&gt;

&lt;p&gt;This is a bit field that represents the state of the thread.&amp;#160; So, you put the value from the State field into the !ThreadState command and you get the current state of that thread.&amp;#160; For example:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;0:000&amp;gt; !threadstate a020
    Legal to Join
    CoInitialized
    In Multi Threaded Apartment&lt;/pre&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;!GCWhere&lt;/strong&gt;&lt;/font&gt; &lt;/p&gt;

&lt;p&gt;If you give it an object address, it will tell you which generation, heap and segment the object is located in.&amp;#160; For example:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;0:000&amp;gt; !gcwhere 00d1db20 
Address            Gen   Heap   segment      begin      allocated    size
00d1db20            0      0    00d10000     00d11000   00d1e010     0xc(12)&lt;/pre&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;!FindRoots&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;When you are debugging a live process (doesn’t work in a dump file), you can use it to be notified when a collection is occurring on a specific generation:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;0:000&amp;gt; !findroots -gen 0
0:000&amp;gt; g
(c3c.9c0): CLR notification exception - code e0444143 (first chance)
&lt;strong&gt;&lt;font color="#ff0000"&gt;CLR notification: GC - Performing a gen 0 collection. Determined surviving objects...&lt;/font&gt;&lt;/strong&gt;
First chance exceptions are reported before any exception handling.
This exception may be expected and handled.
eax=0012f124 ebx=00000000 ecx=00000000 edx=00000006 esi=0012f1e8 edi=00000003
eip=7c812afb esp=0012f120 ebp=0012f174 iopl=0         nv up ei pl nz na pe nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000206
KERNEL32!RaiseException+0x53:&lt;/pre&gt;

&lt;p&gt;Then, at this point, you can give !findroots an object address to get the cross-generational references to the object, for example (from the help file):&lt;/p&gt;

&lt;pre class="csharpcode"&gt;0:002&amp;gt; !findroots 06808094 
        older generations::Root:  068012f8(AAA.Test+a)-&amp;gt;
        06808094(AAA.Test+b)&lt;/pre&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;!HeapStat&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;Will list out where the managed memory falls in the various heaps:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;0:000&amp;gt; !heapstat
Heap             Gen0         Gen1         Gen2          LOH
Heap0          193888           12           12        16976

Free space:                                                     Percentage
Heap0              12           0            0           80     SOH:  0% LOH:  0%&lt;/pre&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;&lt;font size="2"&gt;&lt;strong&gt;!AnalyzeOOM&lt;/strong&gt;&lt;/font&gt;&lt;/p&gt;

&lt;p&gt;When an OutOfMemoryException occurs, you can execute this command to do some preliminary analysis on why the OOM is occurring.&amp;#160; For example:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;0:000&amp;gt; !analyzeoom
&lt;font color="#ff0000"&gt;Managed OOM occured after GC #8 (Requested to allocate 100000016 bytes)
Reason: Didn't have enough memory to commit&lt;/font&gt;&lt;/pre&gt;

&lt;p&gt;I think that’s it at an initial glance.&amp;#160; Please feel free to comment if I’ve missed anything.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=584" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/SOS/default.aspx">SOS</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/WinDBG/default.aspx">WinDBG</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/.NET+4.0/default.aspx">.NET 4.0</category></item><item><title>When are my LINQ db connections closed?</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2009/08/27/When-are-my-LINQ-db-connections-closed_3F00_.aspx</link><pubDate>Thu, 27 Aug 2009 19:30:32 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:583</guid><dc:creator>Greg</dc:creator><slash:comments>0</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/583.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=583</wfw:commentRss><description>&lt;p&gt;So, I was working with a customer who is writing their first application using LINQ.&amp;#160; They had previously been bitten by the failure to close and dispose their &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx" target="_blank"&gt;SqlConnection&lt;/a&gt; objects.&amp;#160; This is actually a fairly common problem and usually leads to those pesky &lt;a href="http://www.15seconds.com/issue/040830.htm" target="_blank"&gt;SqlExceptions detailing that there are no connections left in the pool&lt;/a&gt;.&amp;#160; &lt;/p&gt;  &lt;p&gt;So, since LINQ to SQL abstracts out much of the direct database interaction, they were concerned about when the underlying SqlConnections are closed.&amp;#160;&amp;#160; I will walk through how I answered their question using a few of my favorite tools:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;&lt;a href="http://www.microsoft.com/express/download/" target="_blank"&gt;Visual C# Express&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;a href="http://www.microsoft.com/whdc/devtools/debugging/installx86.mspx#a" target="_blank"&gt;Debugging Tools for Windows&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;To start off, I created a simple SQL Table called Users:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://samuraiprogrammer.com/community/blogimages/LINQDataContextConnections_1164C/UserTable.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="UserTable" border="0" alt="UserTable" src="http://samuraiprogrammer.com/community/blogimages/LINQDataContextConnections_1164C/UserTable_thumb.png" width="393" height="120" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Then, I created a simple LINQ to SQL dbml:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://samuraiprogrammer.com/community/blogimages/LINQDataContextConnections_1164C/Linq2SqlDBML.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="Linq2SqlDBML" border="0" alt="Linq2SqlDBML" src="http://samuraiprogrammer.com/community/blogimages/LINQDataContextConnections_1164C/Linq2SqlDBML_thumb.png" width="244" height="196" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;Now that the plumbing is in place, I can write some simple code to return the data from the table and display it to the console window:&lt;/p&gt;  &lt;p&gt;&lt;/p&gt;  &lt;pre class="csharpcode"&gt;            LinqConnectionSampleDataContext db = 
                &lt;span class="kwrd"&gt;new&lt;/span&gt; LinqConnectionSampleDataContext();

            Table&amp;lt;User&amp;gt; users = db.GetTable&amp;lt;User&amp;gt;();
           
            IQueryable&amp;lt;User&amp;gt; userQuery =
                from user &lt;span class="kwrd"&gt;in&lt;/span&gt; users
                orderby user.firstName
                select user;
                

            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (User user &lt;span class="kwrd"&gt;in&lt;/span&gt; userQuery)
            {

                Console.WriteLine(&lt;span class="str"&gt;&amp;quot;ID={0}, First Name={1}&amp;quot;&lt;/span&gt;, 
                                    user.id, 
                                    user.firstName);&lt;/pre&gt;
So, now when the application is executed, the output is as follows: 

&lt;p&gt;&lt;a href="http://samuraiprogrammer.com/community/blogimages/LINQDataContextConnections_1164C/ConsoleSampleOutput.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="ConsoleSampleOutput" border="0" alt="ConsoleSampleOutput" src="http://samuraiprogrammer.com/community/blogimages/LINQDataContextConnections_1164C/ConsoleSampleOutput_thumb.png" width="644" height="91" /&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&amp;#160;&lt;/p&gt;

&lt;p&gt;So, since Linq to Sql uses an underlying SqlConnection to do its work, we can set a breakpoint on the Close() method of that class in WinDBG.&amp;#160; If you are unfamiliar with this great debugging tool, you can find a simple walkthrough on how to set it up &lt;a href="http://blogs.msdn.com/johan/archive/2007/11/13/getting-started-with-windbg-part-i.aspx" target="_blank"&gt;here&lt;/a&gt;.&amp;#160; &lt;/p&gt;

&lt;p&gt;There are a number of ways to set a breakpoint in managed code in WinDBG.&amp;#160; Here are the steps that I followed:&lt;/p&gt;

&lt;p&gt;Step 1.&amp;#160; Launch WinDBG and attach to the process in question.&lt;/p&gt;

&lt;p&gt;&lt;a href="http://samuraiprogrammer.com/community/blogimages/LINQDataContextConnections_1164C/Windbg_AttachToProcess_RedCircle2.png"&gt;&lt;img style="border-bottom:0px;border-left:0px;display:block;float:none;margin-left:auto;border-top:0px;margin-right:auto;border-right:0px;" title="Windbg_AttachToProcess_RedCircle2" border="0" alt="Windbg_AttachToProcess_RedCircle2" src="http://samuraiprogrammer.com/community/blogimages/LINQDataContextConnections_1164C/Windbg_AttachToProcess_RedCircle2_thumb.png" width="425" height="621" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;&lt;/p&gt;

&lt;p&gt;Step 2.&amp;#160; Load the SOS extension into WinDBG by executing:&lt;/p&gt;

&lt;p align="center"&gt;&lt;strong&gt;.loadby sos mscorwks&lt;/strong&gt;&lt;/p&gt;

&lt;p align="left"&gt;Step 3.&amp;#160; Set the managed breakpoint using the !bpmd command.&amp;#160; For this step, the !bpmd command accepts a variety of parameters.&amp;#160; Basically, you can pass it either:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;div align="left"&gt;MethodDescr address.&lt;/div&gt;
  &lt;/li&gt;

  &lt;li&gt;
    &lt;div align="left"&gt;Combination of Module Name and Managed Function Name&lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p align="left"&gt;I chose the latter method because it’s relatively quick and I knew exactly what I wanted.&amp;#160; So, the syntax for this method is:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p align="left"&gt;!bpmd &amp;lt;module name&amp;gt; &amp;lt;managed function name&amp;gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p align="left"&gt;You can get the module name from visiting the &lt;a href="http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.aspx" target="_blank"&gt;SqlConnection page up on MSDN&lt;/a&gt;.&amp;#160; On this page, we can get the module name and the namespace to the class:&lt;/p&gt;

&lt;p align="left"&gt;&lt;a href="http://samuraiprogrammer.com/community/blogimages/LINQDataContextConnections_1164C/MSDN_sqlconnection.png"&gt;&lt;img style="border-right-width:0px;display:block;float:none;border-top-width:0px;border-bottom-width:0px;margin-left:auto;border-left-width:0px;margin-right:auto;" title="MSDN_sqlconnection" border="0" alt="MSDN_sqlconnection" src="http://samuraiprogrammer.com/community/blogimages/LINQDataContextConnections_1164C/MSDN_sqlconnection_thumb.png" width="425" height="136" /&gt;&lt;/a&gt; &lt;/p&gt;

&lt;p&gt;From this, we can get both parameters necessary:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Module Name:&amp;#160; &lt;strong&gt;System.Data.dll&lt;/strong&gt; &lt;/li&gt;

  &lt;li&gt;Managed Function Name:&amp;#160;&amp;#160; &lt;strong&gt;System.Data.SqlClient.SqlConnection.Close&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So, our command in WinDBG becomes:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;!bpmd System.Data.dll System.Data.SqlClient.SqlConnection.Close&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once you enter in this command, you should get output similar to the following in the WinDBG window:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;0:014&amp;gt; !bpmd System.Data.dll System.Data.SqlClient.SqlConnection.Close
Found 1 methods...
MethodDesc = 544a0418
Setting breakpoint: bp 5455DC80 [System.Data.SqlClient.SqlConnection.Close()]&lt;/pre&gt;

&lt;p&gt;Step 4.&amp;#160; “Go” in the debugger and wait for your breakpoint to be hit.&amp;#160; &lt;/p&gt;

&lt;p&gt;For this, the command is simply “g”.&lt;/p&gt;

&lt;pre class="csharpcode"&gt;0:014&amp;gt; g&lt;/pre&gt;

&lt;p&gt;Eventually, your breakpoint will be hit in the debugger and you should get output similar to the following:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;Breakpoint 0 hit
eax=5457da68 ebx=04d7e9dc ecx=0185cd30 edx=018e56b0 esi=01870d80 edi=04d7e9a4
eip=5455dc80 esp=04d7e860 ebp=04d7e868 iopl=0         nv up ei pl nz na po nc
cs=001b  ss=0023  ds=0023  es=0023  fs=003b  gs=0000             efl=00000202
System_Data_ni+0xcdc80:
5455dc80 55              push    ebp&lt;/pre&gt;

&lt;p&gt;Step 5.&amp;#160; Print out the call-stack.&amp;#160; &lt;/p&gt;

&lt;p&gt;The command to print out the call stack in SOS and WinDBG is “!clrstack”:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;0:008&amp;gt; !clrstack&lt;/pre&gt;

&lt;p&gt;This will print out the managed call stack, which turns out to be:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;OS Thread Id: 0x1d70 (8)
ESP       EIP     
04d7e860 5455dc80 System.Data.SqlClient.SqlConnection.Close()
04d7e864 77e20586 System.Data.Linq.SqlClient.SqlConnectionManager
                    .CloseConnection()
04d7e870 77e20554 System.Data.Linq.SqlClient.SqlConnectionManager
                    .ReleaseConnection(...)
04d7e87c 77e1da35 System.Data.Linq.SqlClient.
        ObjectReaderCompiler+ObjectReaderSession`1[...].Dispose()
04d7e888 77e1ddac System.Data.Linq.SqlClient.
        ObjectReaderCompiler+ObjectReaderSession`1[...].CheckNextResults()
04d7e894 77e1df2c System.Data.Linq.SqlClient.
        ObjectReaderCompiler+ObjectReaderBase`1[...].Read()
04d7e8a0 77e1ea2d System.Data.Linq.SqlClient.
        ObjectReaderCompiler+ObjectReader`2[...].MoveNext()
04d7e8ac 004f1a12 LINQ.SqlConnection.Program.Main(System.String[])&lt;/pre&gt;

&lt;p&gt;So, if you’re having trouble parsing this, the take away here is that when you iterate through a Linq resultset and you get to the end, the ObjectReaderSession will automatically close the Connection to the database.&lt;/p&gt;

&lt;p&gt;Now, this is a simple HelloWorld code sample for retrieving a result-set and there are obviously a number of ways to do the same thing.&amp;#160; The customer’s code was closer to the following:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;using&lt;/span&gt; (IEnumerator&amp;lt;User&amp;gt; enumerator = 
          context.ExecuteQuery&amp;lt;User&amp;gt;(sqlStatement).GetEnumerator())
{

       &lt;span class="kwrd"&gt;while&lt;/span&gt; (enumerator.MoveNext())
       {

              &lt;span class="rem"&gt;// Do something here&lt;/span&gt;

        }

}&lt;/pre&gt;

&lt;p&gt;In this situation, we get an IEnumerator&amp;lt;T&amp;gt; back from the database call and iterate through it.&amp;#160; &lt;strong&gt;Now, this part is very important.&lt;/strong&gt;&amp;#160; If you are iterating through the result set to completion – the connection will be closed the same as the above.&amp;#160; However, if you do something like this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;            &lt;span class="kwrd"&gt;using&lt;/span&gt; (IEnumerator&amp;lt;User&amp;gt; enumerator = 
                db.ExecuteQuery&amp;lt;User&amp;gt;(sqlStatement).GetEnumerator())
            {
                &lt;span class="kwrd"&gt;while&lt;/span&gt; (enumerator.MoveNext())
                {

                    Console.WriteLine(&lt;span class="str"&gt;&amp;quot;ID={0}, First Name={1}&amp;quot;&lt;/span&gt;, 
                        enumerator.Current.id, 
                        enumerator.Current.firstName);
                    
                    &lt;span class="rem"&gt;// Stop iterating after this record.&lt;/span&gt;
                    &lt;span class="kwrd"&gt;break&lt;/span&gt;;

                }

            }&lt;/pre&gt;

&lt;p&gt;Please note the “break” statement.&amp;#160; Essentially, if you are NOT iterating through to completion, the call stack looks like:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;OS Thread Id: 0x251c (11)
ESP       EIP     
0522e73c 5455dc80 System.Data.SqlClient.SqlConnection.
                    Close()
0522e740 77e20586 System.Data.Linq.SqlClient.SqlConnectionManager.
                    CloseConnection()
0522e74c 77e20554 System.Data.Linq.SqlClient.SqlConnectionManager.
                    ReleaseConnection(...)
0522e758 77e1da35 System.Data.Linq.SqlClient.ObjectReaderCompiler+
                    ObjectReaderSession`1[...].Dispose()
0522e764 77e1ea12 System.Data.Linq.SqlClient.ObjectReaderCompiler+
                    &lt;font color="#ff0000"&gt;ObjectReader`2[...].Dispose()&lt;/font&gt;
0522e768 00691bde LINQ.SqlConnection.Program.Main(System.String[])&lt;/pre&gt;

&lt;p&gt;&lt;strong&gt;The connection will NOT be closed until you call Dispose() on the ObjectReader (IEnumerable) object.&lt;/strong&gt;&amp;#160; This means that if you happen to write some code without the Using… statement when returning data like this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;            IEnumerator&amp;lt;User&amp;gt; enumerator =
                db.ExecuteQuery&amp;lt;User&amp;gt;(sqlStatement).GetEnumerator();

            &lt;span class="kwrd"&gt;while&lt;/span&gt; (enumerator.MoveNext())
            {

                Console.WriteLine(&lt;span class="str"&gt;&amp;quot;ID={0}, First Name={1}&amp;quot;&lt;/span&gt;,
                    enumerator.Current.id,
                    enumerator.Current.firstName);

                &lt;span class="rem"&gt;// Stop iterating after this record.&lt;/span&gt;
                &lt;span class="kwrd"&gt;break&lt;/span&gt;;

            }&lt;/pre&gt;

&lt;p&gt;The SqlConnection.Close() method will &lt;strong&gt;NOT&lt;/strong&gt; be called.&amp;#160; This is because you have full control over the lifetime of the IEnumerator&amp;lt;T&amp;gt; object and you should know when you are done with it.&amp;#160; &lt;/p&gt;

&lt;p&gt;Now, along those lines, you may be asking yourself – what if I did something like this:&lt;/p&gt;

&lt;pre class="csharpcode"&gt;            LinqConnectionSampleDataContext db = 
                &lt;span class="kwrd"&gt;new&lt;/span&gt; LinqConnectionSampleDataContext();

            Table&amp;lt;User&amp;gt; users = db.GetTable&amp;lt;User&amp;gt;();
           
            IQueryable&amp;lt;User&amp;gt; userQuery =
                from user &lt;span class="kwrd"&gt;in&lt;/span&gt; users
                orderby user.firstName
                select user;
                

            &lt;span class="kwrd"&gt;foreach&lt;/span&gt; (User user &lt;span class="kwrd"&gt;in&lt;/span&gt; userQuery)
            {

                Console.WriteLine(&lt;span class="str"&gt;&amp;quot;ID={0}, First Name={1}&amp;quot;&lt;/span&gt;, 
                                    user.id, 
                                    user.firstName);

                &lt;font color="#ff0000"&gt;&lt;font size="4"&gt;&lt;span class="kwrd"&gt;break&lt;/span&gt;;&lt;/font&gt;&lt;/font&gt;
            }&lt;/pre&gt;

&lt;p&gt;Where you break before you iterate through to completion?&amp;#160; In that situation, Dispose() will still be called on the IQueryable&amp;lt;T&amp;gt; object.&amp;#160; How?&amp;#160; Because of a compile-time optimization we do.&amp;#160; We insert a finally statement after the userQuery has been used.&amp;#160; This compiles down to (in IL):&lt;/p&gt;

&lt;pre class="csharpcode"&gt;&lt;font color="#ff0000" size="4"&gt; try{&lt;/font&gt;&lt;br /&gt;    L_005d: br.s L_0084
    L_005f: ldloc.s CS$5$0002
    L_0061: callvirt instance !0...get_Current()
    L_0066: stloc.3 
    L_0067: ldstr &lt;span class="str"&gt;&amp;quot;ID={0}, First Name={1}&amp;quot;&lt;/span&gt;
    L_006c: ldloc.3 
    L_006d: callvirt instance int32 LINQ.SqlConnection.User::get_id()
    L_0072: box int32
    L_0077: ldloc.3 
    L_0078: callvirt instance &lt;span class="kwrd"&gt;string&lt;/span&gt; LINQ.SqlConnection.User::get_firstName()
    L_007d: call &lt;span class="kwrd"&gt;void&lt;/span&gt; [mscorlib]System.Console::WriteLine(&lt;span class="kwrd"&gt;string&lt;/span&gt;, &lt;span class="kwrd"&gt;object&lt;/span&gt;, &lt;span class="kwrd"&gt;object&lt;/span&gt;)
    L_0082: br.s L_008d
    L_0084: ldloc.s CS$5$0002
    L_0086: callvirt instance &lt;span class="kwrd"&gt;bool&lt;/span&gt; [mscorlib]System.Collections.IEnumerator::MoveNext()
    L_008b: brtrue.s L_005f
    L_008d: leave.s L_009b&lt;br /&gt;  &lt;font color="#ff0000" size="4"&gt;}finally{&lt;br /&gt;&lt;/font&gt;    L_008f: ldloc.s CS$5$0002
    L_0091: brfalse.s L_009a
    L_0093: ldloc.s CS$5$0002
    L_0095: callvirt instance &lt;span class="kwrd"&gt;void&lt;/span&gt; [mscorlib]System.IDisposable::Dispose()
    L_009a: endfinally&lt;br /&gt;  &lt;font color="#ff0000" size="4"&gt;}&lt;/font&gt; 
    L_009b: ret 
    .&lt;span class="kwrd"&gt;try&lt;/span&gt; L_005d to L_008f &lt;span class="kwrd"&gt;finally&lt;/span&gt; handler L_008f to L_009b&lt;/pre&gt;

&lt;p&gt;The text in red is my emphasis.&amp;#160; So, the moral of this story, when you take control of the data yourself, you MUST call dispose on the IEnumerable&amp;lt;T&amp;gt; object when you are done with it.&lt;/p&gt;

&lt;p&gt;Enjoy!&lt;/p&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=583" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/.NET/default.aspx">.NET</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/LINQ/default.aspx">LINQ</category></item><item><title>Working for Microsoft: Week 98</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2009/08/19/Working-for-Microsoft_3A00_-Week-98.aspx</link><pubDate>Thu, 20 Aug 2009 05:06:44 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:582</guid><dc:creator>Greg</dc:creator><slash:comments>0</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/582.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=582</wfw:commentRss><description>&lt;p&gt;So, I was listening/watching a Hanselman webcast today and I journeyed over to my site and realized that I haven’t blogged anything in almost 2 years.&amp;#160; There are certainly some reasons for it but being we have just started a new fiscal year, I thought I would try to step-it-up a bit.&amp;#160; &lt;/p&gt;  &lt;p&gt;&lt;strong&gt;First, some house-cleaning.&amp;#160; About 97 weeks ago, I had to turn off anonymous comments.&amp;#160; I’m not happy about it but the amount of spam that I got in my blog comments was ridiculous.&amp;#160; Eventually I’ll upgrade the blog engine to include some captcha stuff but until then feel free to shoot me messages if you don’t want to register.&lt;/strong&gt;&lt;/p&gt;  &lt;p&gt;In any case, on with the show.&amp;#160; The obvious question is – what have I been doing during these weeks?&amp;#160; Well, the obvious answer is that I’ve been working a lot.&amp;#160; A large part of my (newish) job at Microsoft is traveling to customers and helping them with their applications.&amp;#160; As a result, while I’ve gained a lot of status with airlines and hotels, it hasn’t left me with a lot of time to spend on this medium.&amp;#160; I’ve set some things in motion to free up more of that time so expect to see some more entries coming soon.&lt;/p&gt;  &lt;p&gt;In the interim, I have been involved in the community in small ways for a while via 2 social media platforms:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Twitter – &lt;a href="http://twitter.com/varveris"&gt;http://twitter.com/varveris&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;Facebook – &lt;a href="http://facebook.com/gregvarveris"&gt;http://facebook.com/gregvarveris&lt;/a&gt; &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;I’ve also been helping other folks out there in the blogosphere – most notably Jeff Atwood of &lt;a href="http://codinghorror.com"&gt;Coding Horror.com&lt;/a&gt;.&amp;#160; He had a nasty deadlock on his &lt;a href="http://stackoverflow.com"&gt;StackOverflow.com&lt;/a&gt; site related to his use of log4net.&amp;#160; You can read more about the work I did with him &lt;a href="http://www.codinghorror.com/blog/archives/001192.html"&gt;here&lt;/a&gt;.&amp;#160; I’ll post my version of the tale at a later date as it’s an interesting problem and while Jeff’s solution worked – it was a bit extreme.&lt;/p&gt;  &lt;p&gt;So, work-wise, what have I been doing as a Premier Field Engineer? Well, it is generally broken into 2 areas – reactive and proactive work.&amp;#160; &lt;/p&gt;  &lt;p&gt;The reactive work is where a customer is experiencing a problem (usually in production) and they need someone onsite to help the resolve the issue.&amp;#160; These are generally pretty fun and challenging.&amp;#160; &lt;/p&gt;  &lt;p&gt;The proactive work is more along the lines of:&lt;/p&gt;  &lt;ul&gt;   &lt;li&gt;Workshops &lt;/li&gt;    &lt;li&gt;White Boarding Sessions (Chalk Talks) &lt;/li&gt;    &lt;li&gt;Code Reviews &lt;/li&gt;    &lt;li&gt;Performance Optimizations &lt;/li&gt;    &lt;li&gt;Bottleneck Analysis &lt;/li&gt;    &lt;li&gt;Scalability Reviews &lt;/li&gt;    &lt;li&gt;Architecture Reviews &lt;/li&gt;    &lt;li&gt;Proofs of Concepts &lt;/li&gt;    &lt;li&gt;etc… &lt;/li&gt; &lt;/ul&gt;  &lt;p&gt;The above are challenging as well – but in a different way.&amp;#160; I love to teach and help people write better code – and both categories allow me to do that – so I’m good. &lt;/p&gt;  &lt;p&gt;Of course, we also get the items in between.&amp;#160; For example, I had a customer with a custom ISAPI filter that needed to be upgraded from Windows 2000 to Windows Server 2003.&amp;#160; Because the model changed a bit from IIS 5 to IIS 6, we needed to overhaul some of that ISAPI code.&amp;#160; Oh, did I mention that the filter was written in VC++ 6.0?&amp;#160; Yeah, we upgraded that as well to the latest and greatest.&amp;#160; All over 2 weeks.&amp;#160; &lt;/p&gt;  &lt;p&gt;So, in addition to that stuff, I’ve also written some tools (some public, most private), created workshops and achieved Premier Executive status on United airlines and Platinum status with Marriott.&amp;#160; It’s been a fun 98 weeks.&amp;#160; Can’t wait to see what happens next.&lt;/p&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=582" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Development/default.aspx">Development</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Working+for+Microsoft/default.aspx">Working for Microsoft</category></item><item><title>Working for Microsoft:  Week 1</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2007/10/14/Working-for-Microsoft_3A00_--Week-1.aspx</link><pubDate>Sun, 14 Oct 2007 22:10:02 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:570</guid><dc:creator>Greg</dc:creator><slash:comments>1</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/570.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=570</wfw:commentRss><description>&lt;p&gt;&lt;a href="http://www.samuraiprogrammer.com/community/blogimages/WorkingforMicrosoftWeek1_D59B/me.png"&gt;&lt;img id="id" style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="148" alt="me" src="http://www.samuraiprogrammer.com/community/blogimages/WorkingforMicrosoftWeek1_D59B/me_thumb.png" width="104" align="right" border="0" /&gt;&lt;/a&gt; Initially I was planning to blog every day or so about my experiences within Microsoft, but alas, this has been the first free moment I've had so far after my last post.&amp;#xA0; The reason?&amp;#xA0; Well, as I mentioned in a previous post, the first three weeks of my new career are spent at something called &amp;quot;MSSU&amp;quot; (Microsoft Services University).&amp;#xA0; This is affectionately referred to as &amp;quot;Boot Camp&amp;quot; by those in the know.&amp;#xA0; The boot camp analogy is not far from the truth, I must say.&amp;#xA0; Having never gone through boot camp in the traditional sense of the term, having never been in the armed services, I referred to &lt;a href="http://www.military.com/Recruiting/Content/0,13898,rec_step09_bootcamp_surviving,,00.html" target="_blank"&gt;a military site&lt;/a&gt; and realized&amp;#xA0; that it has been pretty close to my experience, thus far - Minus the disparaging drill sergeant type atmosphere.&lt;/p&gt;  &lt;p&gt;Basically, the intention is to get us up to speed on Microsoft, the products, tools, etc. as fast as possible.&amp;#xA0; Most days start with a 7am shuttle ride to one of the campuses and then you are in class until sometime after 5pm'ish.&amp;#xA0; So, here's a few things I've learned in my relatively short tenure:&lt;/p&gt;  &lt;ol&gt;   &lt;li&gt;&lt;strong&gt;Be Prepared to Eat Well -&lt;/strong&gt; When I was in college, they had something they called the &amp;quot;Freshman 15&amp;quot;.&amp;#xA0; Basically, in the first semester of college, you expect to gain about 15 pounds.&amp;#xA0; I think I am going to start the &amp;quot;Microsoft 15&amp;quot;.&amp;#xA0; Every day, I am given 3 square meals.&amp;#xA0; Breakfast usually consists of eggs, bacon, etc.&amp;#xA0; Lunch is usually a trip to one of the many Cafeterias on campus.&amp;#xA0; You're usually on your own for dinner, but they have a lot restaurants within walking distance from the Apartments.&amp;#xA0; It has been years since I've consistently eaten 3 square meals.&amp;#xA0; I'm going to have to start hitting the gym while I'm here. &lt;a href="http://www.samuraiprogrammer.com/community/blogimages/WorkingforMicrosoftWeek1_D59B/IMG00086.jpg"&gt;&lt;img id="id" style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" height="184" alt="IMG00086" src="http://www.samuraiprogrammer.com/community/blogimages/WorkingforMicrosoftWeek1_D59B/IMG00086_thumb.jpg" width="244" align="right" border="0" /&gt;&lt;/a&gt; &lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Be Prepared to Work&lt;/strong&gt; - As I mentioned above - each day starts at 7am and goes late.&amp;#xA0; During that time, you will learn about the MS Products, the Tools available, the culture, etc.&amp;#xA0; Everyone pretty much uses OneNote to track all of the various information provided.&amp;#xA0; In the past, I would generally use a Text editor to take notes - but I have certainly started drinking the OneNote kool-aid.&amp;#xA0; It's a great tool and I wish I had had a license in my previous life.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Take the Time to Socialize&lt;/strong&gt; - It's not often I have gone through a training regiment where everyone is really intelligent.&amp;#xA0; Most people are smart, no doubt about that, but at a class like this - everyone is scary smart.&amp;#xA0; Part of this boot camp is meant to allow you to build relationships with other people in your position.&amp;#xA0; Chances are, you will be communicating with these same people throughout your career.&amp;#xA0; It really behooves you to get to know them and build those relationships now.&amp;#xA0; Every night, the other PFE's and I have gone out for drinks and dinner and the conversations have ranged from Exchange to .NET to Active Directory to Windows Server to BizTalk to SQL Server.&amp;#xA0; Everything is fair game and you will learn a lot about a ton of products during these informal conversations.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Set up your Outlook Rules&lt;/strong&gt; - As &lt;a href="http://www.hanselman.com/blog/GettingOrganizedWhileDrinkingFromTheOutlookFireHose.aspx" target="_blank"&gt;Scott Hanselman mentions here&lt;/a&gt;, one of the things that has amazed me so far are all of the e-mails that get sent around.&amp;#xA0; In my third day or so on the job, I opened up my inbox and had several HUNDRED e-mails there waiting for me.&amp;#xA0; Therefore, it was a necessity to starting setting up my Outlook rules and start the forwarding process into folders.&amp;#xA0; I'm sure as I get added to more and more lists, my rules list will get longer and longer.&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Start Making Redmond/Seattle Connections&lt;/strong&gt; - During my first day at NEO, I got a call from a .NET PFE based out of Redmond welcoming me to the team.&amp;#xA0; Since there are few other .NET PFE's starting, he offered to go out for drinks one night to pick his brain.&amp;#xA0; I highly highly highly recommend doing this.&amp;#xA0; I learned more about the position and what challenges I will be facing during that few hour session than I did throughout the several week hiring process.&amp;#xA0; The bottom-line is that the culture of MS is to help your peers and other employees.&amp;#xA0; Truly incredible.&lt;a href="http://www.samuraiprogrammer.com/community/blogimages/WorkingforMicrosoftWeek1_D59B/IMG00091.jpg"&gt;&lt;img style="border-right:0px;border-top:0px;margin:4px 4px 4px 8px;border-left:0px;border-bottom:0px;" height="184" alt="IMG00091" src="http://www.samuraiprogrammer.com/community/blogimages/WorkingforMicrosoftWeek1_D59B/IMG00091_thumb.jpg" width="244" align="right" border="0" /&gt;&lt;/a&gt;&lt;/li&gt;    &lt;li&gt;&lt;strong&gt;Explore the Campus&lt;/strong&gt; - Although, you may not be located in Redmond, that doesn't mean you shouldn't take a walk around the campus and pop into the offices.&amp;#xA0; As part of a team building event yesterday we had to walk around the campus.&amp;#xA0; It was truly a great experience and I got to see the homes of teams that I've long followed as an external admirer.&amp;#xA0; For example, just imagine sitting in Bill Gates' old office in Redmond.&amp;#xA0; You get a real sense of history in certain areas.&amp;#xA0; Very cool stuff.&lt;/li&gt; &lt;/ol&gt;  &lt;p&gt;Honestly, I think most of these things can be applied to anyone starting a new job, but it just may be more prevalent in a MS field based role.&lt;/p&gt;  &lt;p&gt;Overall, I've really enjoyed myself.&amp;#xA0; So far, this has been an incredible experience and I can't wait for the next 2 weeks.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;  &lt;p&gt;&amp;#xA0;&lt;/p&gt;  &lt;div class="wlWriterSmartContent" id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:b521ee80-2e6c-429e-b777-c1699ab44273" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags:  		&lt;a href="http://technorati.com/tags/Working%20For%20Microsoft/" rel="tag"&gt;Working For Microsoft&lt;/a&gt; 		,  		&lt;a href="http://technorati.com/tags/Microsoft/" rel="tag"&gt;Microsoft&lt;/a&gt; 		&lt;/div&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=570" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Microsoft/default.aspx">Microsoft</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Working+for+Microsoft/default.aspx">Working for Microsoft</category></item><item><title>Working at Microsoft:  Day 1</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2007/10/08/Working-at-Microsoft_3A00_--Day-1.aspx</link><pubDate>Tue, 09 Oct 2007 01:59:00 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:114</guid><dc:creator>Greg</dc:creator><slash:comments>2</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/114.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=114</wfw:commentRss><description>&lt;p&gt;Well, I have officially been in the Seattle area for about 24 hours.&amp;nbsp; My flight in was fine and yes, the weather was cold and rainy.&amp;nbsp; I&amp;#39;m very happy that I picked up a raincoat before I left.&amp;nbsp; &lt;/p&gt;  &lt;p&gt;After arriving and checking into my long term housing, I took a walk around the area and ended up at a nice little bar and grille called &lt;a href="http://www.yelp.com/biz/5oEN43xSSh5iwT7clr5XMA" target="_blank"&gt;520&lt;/a&gt; in Bellevue to catch the second half of the Bears game - and for once, the Bears didn&amp;#39;t lose.&amp;nbsp; I consider that a good omen.&lt;/p&gt;  &lt;p&gt;Here&amp;#39;s a pic of my home for the next 3 weeks:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.samuraiprogrammer.com/community/blogimages/WorkingatMicrosoftDay1_12050/IMG00071.jpg"&gt;&lt;img id="id" style="border:0px none;margin:1px;" src="http://www.samuraiprogrammer.com/community/blogimages/WorkingatMicrosoftDay1_12050/IMG00071_thumb.jpg" border="0" alt="IMG00071" width="240" height="180" /&gt;&lt;/a&gt;&lt;/p&gt;  &lt;p&gt;The view from the apartment:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.samuraiprogrammer.com/community/blogimages/WorkingatMicrosoftDay1_12050/IMG00080.jpg"&gt;&lt;img id="id" style="border:0px none;" src="http://www.samuraiprogrammer.com/community/blogimages/WorkingatMicrosoftDay1_12050/IMG00080_thumb.jpg" border="0" alt="IMG00080" width="240" height="180" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The next morning, the other PFE&amp;#39;s and myself took a nice shuttle ride from our housing to the Microsoft campus.&amp;nbsp; We knew we had arrived when we saw this:&lt;/p&gt;  &lt;p&gt;&lt;a href="http://www.samuraiprogrammer.com/community/blogimages/WorkingatMicrosoftDay1_12050/IMG00077.jpg"&gt;&lt;img id="id" style="border:0px none;" src="http://www.samuraiprogrammer.com/community/blogimages/WorkingatMicrosoftDay1_12050/IMG00077_thumb.jpg" border="0" alt="IMG00077" width="240" height="180" /&gt;&lt;/a&gt; &lt;a href="http://www.samuraiprogrammer.com/community/blogimages/WorkingatMicrosoftDay1_12050/IMG00078.jpg"&gt;&lt;img id="id" style="border:0px none;" src="http://www.samuraiprogrammer.com/community/blogimages/WorkingatMicrosoftDay1_12050/IMG00078_thumb.jpg" border="0" alt="IMG00078" width="240" height="180" /&gt;&lt;/a&gt; &lt;/p&gt;  &lt;p&gt;The entire day was spent in New Employee Orientation.&amp;nbsp; The day was good, learning much about the company and the tools available to us as Microsoft employees.&lt;/p&gt;  &lt;p&gt;This new stage in my career is finally beginning to feel real.&amp;nbsp; I expect it will feel even more so the longer I&amp;#39;m out here.&lt;/p&gt;  &lt;p&gt;I&amp;#39;m still working on the samples for the SamuraiProgrammer.Web.UI - and I should have that up soon.&lt;/p&gt;  &lt;p&gt;Enjoy!&lt;/p&gt;  &lt;div id="scid:0767317B-992E-4b12-91E0-4F059A8CECA8:3b4f10a4-fb62-48cb-87bd-e6a828b07959" class="wlWriterSmartContent" style="margin:0px;padding:0px;display:inline;"&gt;Technorati Tags:  		&lt;a rel="tag" href="http://technorati.com/tags/Working%20For%20Microsoft/"&gt;Working For Microsoft&lt;/a&gt; 		,  		&lt;a rel="tag" href="http://technorati.com/tags/.NET/"&gt;.NET&lt;/a&gt; 		,  		&lt;a rel="tag" href="http://technorati.com/tags/Microsoft/"&gt;Microsoft&lt;/a&gt; 		&lt;/div&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=114" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Microsoft/default.aspx">Microsoft</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/.NET/default.aspx">.NET</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Working+for+Microsoft/default.aspx">Working for Microsoft</category></item><item><title>Releasing the Source Code for .NET</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2007/10/03/Releasing-the-Source-Code-for-.NET.aspx</link><pubDate>Thu, 04 Oct 2007 06:42:34 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:113</guid><dc:creator>Greg</dc:creator><slash:comments>0</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/113.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=113</wfw:commentRss><description>&lt;p&gt;I was just about to head to sleep when I read &lt;a href="http://weblogs.asp.net/scottgu/archive/2007/10/03/releasing-the-source-code-for-the-net-framework-libraries.aspx" target="_blank"&gt;this great post by Scott Guthrie&lt;/a&gt;.&amp;nbsp; Apparently, Microsoft will be releasing the source code for the BCL (Base Class Libraries), ASP.NET, WinForms, etc. when .NET 3.5 and VS2008 (aka Orcas) is released later this year.&amp;nbsp; &lt;/p&gt; &lt;p&gt;I have to admit that I was looking forward to reading some of that code when I started my new gig over there next week.&amp;nbsp; Silly me, I considered it a perk for working over at MS &amp;lt;grin&amp;gt;.&amp;nbsp; &amp;nbsp;&lt;/p&gt; &lt;p&gt;In any case, us developer type folk could always use &lt;a href="http://www.aisto.com/roeder/dotnet/"&gt;Reflector&lt;/a&gt;&amp;nbsp;to browse through the code, but the level of integration with the IDE (along the line of the Symbol integration) is really slick.&amp;nbsp; Plus, we get to see the comments in that code.&amp;nbsp; I know that they'll probably clean them up prior to release or maybe they won't.&amp;nbsp; I've seen some pretty wacky (and humorous) comments over the years, so I can only imagine the type of things in that code.&lt;/p&gt; &lt;p&gt;Some funny comments I've read that come to mind:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;"It's late, I'm tired and this is as good as it's going to get."&lt;/li&gt; &lt;li&gt;"I know this shouldn't be hardcoded.&amp;nbsp; Leave me alone."&lt;/li&gt; &lt;li&gt;In a summary tag for a method:&amp;nbsp; "Blah blah blah"&lt;/li&gt; &lt;li&gt;I even recall someone that had pasted lyrics into their code comments.&amp;nbsp; Go figure.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;Anyway, now I'm really off to bed.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Enjoy!&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:f6607749-2787-4bf3-bc1f-f5b59629282f" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/.NET" rel="tag"&gt;.NET&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Microsoft" rel="tag"&gt;Microsoft&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Development" rel="tag"&gt;Development&lt;/a&gt;, &lt;a href="http://technorati.com/tags/VS2008" rel="tag"&gt;VS2008&lt;/a&gt;&lt;/div&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=113" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Microsoft/default.aspx">Microsoft</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/.NET/default.aspx">.NET</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Development/default.aspx">Development</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Visual+Studio/default.aspx">Visual Studio</category></item><item><title>Developers Love Their Tools...</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2007/10/01/Developers-Love-Their-Tools_2E002E002E00_.aspx</link><pubDate>Tue, 02 Oct 2007 05:08:23 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:111</guid><dc:creator>Greg</dc:creator><slash:comments>1</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/111.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=111</wfw:commentRss><description>&lt;p&gt;Seriously, I think there are few things that Developers are more passionate about than the tools and toys they use to code.&amp;nbsp; Carl has compiled a great list of Free Visual Studio 2005 Addins.&amp;nbsp; You can read the list &lt;a href="http://www.carlj.ca/2007/09/25/15-free-visual-studio-add-ins/" target="_blank"&gt;here&lt;/a&gt;.&amp;nbsp; &lt;/p&gt; &lt;p&gt;The addins that I use on a (almost) daily basis for VS 2005 are (in no particular order):&lt;/p&gt; &lt;ul&gt; &lt;li&gt;AnkhSVN&lt;/li&gt; &lt;li&gt;CodeKeep Add-in&lt;/li&gt; &lt;li&gt;GhostDoc 2.1.1 (wish there was a VB version of this one)&lt;/li&gt; &lt;li&gt;Modeling Power Toys&lt;/li&gt; &lt;li&gt;Pinvoke.Net Addin&lt;/li&gt; &lt;li&gt;Refactor! family of Addins&lt;/li&gt; &lt;li&gt;Smart Paster 1.1 (HUGE time saver)&lt;/li&gt; &lt;li&gt;Dpack&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;If you know of one that is not listed on Carl's blog, just drop a comment and he'll evaluate and add it.&amp;nbsp; Please be aware that I think he has a 15-20 addin backlog at this moment.&lt;/p&gt; &lt;p&gt;As Orcas (ahem, Visual Studio 2008) is right around the corner, I'd be interested to see a list of addins for that IDE.&amp;nbsp; Wishful thinking, but if you see a list - drop me a line.&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;Enjoy!&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:091ee16c-3dc6-4a39-a014-ed343fdb49c7" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/VS2005%20Addin" rel="tag"&gt;VS2005 Addin&lt;/a&gt;, &lt;a href="http://technorati.com/tags/VS2005" rel="tag"&gt;VS2005&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Visual%20Studio" rel="tag"&gt;Visual Studio&lt;/a&gt;, &lt;a href="http://technorati.com/tags/.NET" rel="tag"&gt;.NET&lt;/a&gt;&lt;/div&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=111" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Orcas/default.aspx">Orcas</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/.NET/default.aspx">.NET</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Development/default.aspx">Development</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Visual+Studio/default.aspx">Visual Studio</category></item><item><title>Giving XBOX Live a Chance</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2007/09/30/Giving-XBOX-Live-a-Chance.aspx</link><pubDate>Sun, 30 Sep 2007 18:08:38 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:110</guid><dc:creator>Greg</dc:creator><slash:comments>0</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/110.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=110</wfw:commentRss><description>&lt;p&gt;I am far from a hardcore gamer.&amp;nbsp; I don't log on and play for hours upon hours because well,&amp;nbsp;I just don't have that much spare time to play.&amp;nbsp; It's a shame, but hey, that's life.&amp;nbsp; In any case, one thing that I've been meaning to do for years was sign up for an XBOX Live membership.&amp;nbsp; Several of my friends are avid gamers and have weekly Thursday night Halo battles (was Halo 2 and now it's Halo 3).&amp;nbsp; One of my closest friends has been trying to get me online for years to join them but I never took them up on it.&lt;/p&gt; &lt;p&gt;The main reason that I never signed up was because I simply didn't have any free ports on my Router.&amp;nbsp; I know that's a lame reason, but it's true.&amp;nbsp; I only had a 4 port router - with Wireless - but with a few servers, a few desktops and a laptop (or 2) in my home office my measly 4 ports were filled up pretty quickly.&amp;nbsp; And Yes, I could have purchased the &lt;a href="http://www.xbox.com/en-US/hardware/x/xbox360wirelessnetadapter/" target="_blank"&gt;XBOX 360 Wireless Netowrking Adapter&lt;/a&gt;&amp;nbsp;but maybe I'm just old school in that I always worry about network lag when I'm wirelessly gaming.&amp;nbsp; I remember when I was first playing some online games on my PC back in the day (ie:&amp;nbsp; 10 years ago), specifically &lt;a href="http://www.gamespot.com/pc/action/jediknightdarkforces2/index.html" target="_blank"&gt;Star Wars Jedi Knight: Dark Forces II&lt;/a&gt;,&amp;nbsp;network lag was a big issue in the online component.&amp;nbsp; I would be having a heated Light Saber duel and my opponent would disappear for a second or two.&amp;nbsp; All of a sudden, he would reappear and I'd be dead having taken a Saber hit to my head.&amp;nbsp; Aaah, those were the days.&amp;nbsp; :: Sigh :: &lt;/p&gt; &lt;p&gt;Well, last night, since I was already at &lt;a href="http://www.microcenter.com/" target="_blank"&gt;Micro Center&lt;/a&gt;&amp;nbsp;picking up a new &lt;a href="http://www.microcenter.com/single_product_results.phtml?product_id=0240918" target="_blank"&gt;Hard Drive Enclosure&lt;/a&gt;, I stopped by the networking section and picked up a new &lt;a href="http://www.microcenter.com/single_product_results.phtml?product_id=0210221" target="_blank"&gt;8 Port Router&lt;/a&gt;&amp;nbsp;and a new 100 foot cable. I swear, Micro Center is a very very dangerous place for a geek to wander around within.&amp;nbsp; I went there looking to spend about $50 and left spending about 5 times that.&amp;nbsp; :: Grin ::&amp;nbsp; &lt;/p&gt; &lt;p&gt;In any case, once I was home, installation was a breeze - with one caveat.&amp;nbsp; Plastered all over the internal router were these stickers and labels saying "Run the CD before hooking up the router".&amp;nbsp; Skeptical, I did pop in the CD and found it to be a step by step guide on how to plug everything into your network from the perspective of the newbie.&amp;nbsp; What they should have said is - if this is your first router, then run the CD.&amp;nbsp; Oh well - what a waste of about 30 seconds of my time.&amp;nbsp; &lt;/p&gt; &lt;p&gt;After hooking everything up, the XBOX Live membership process was a breeze, although, I couldn't use "SamuraiProgrammer" as my handle (too many characters).&amp;nbsp; I had to settle for something else:&lt;/p&gt; &lt;p align="center"&gt;&lt;a href="http://www.samuraiprogrammer.com/community/blogimages/GivingXBOXLiveaChance_A755/image.png"&gt;&lt;img style="border-right:0px;border-top:0px;border-left:0px;border-bottom:0px;" alt="image" src="http://www.samuraiprogrammer.com/community/blogimages/GivingXBOXLiveaChance_A755/image_thumb.png" border="0"&gt;&lt;/a&gt; &lt;/p&gt; &lt;p&gt;Yes, I realize that my Gamer Score is lame but in all fairness I played the heck out of my original XBOX and none of my achievements (nevermind that they didn't exist back then) carried over to my 360.&amp;nbsp; Feel free to add me to your list of friends and perhaps we can jam on some multiplayer &lt;a href="http://en.wikipedia.org/wiki/Frogger" target="_blank"&gt;Frogger&lt;/a&gt; one day.&amp;nbsp; &lt;/p&gt; &lt;p&gt;I do have&amp;nbsp;a few tiny tiny nitpicks, though.&amp;nbsp; &lt;/p&gt; &lt;p&gt;1.&amp;nbsp; When you are online via the XBOX, you have a lengthy list of icons you can use to decorate your gamer card.&amp;nbsp; However, when you view your gamer card online - you have much fewer.&amp;nbsp; This means that if you pick an icon that is not on the XBOX Live site, your icon will default to the fella featured &lt;img src="https://live.xbox.com/tiles/LD/BM/12dsb2JhbC9BClZWVEoAGAFdL3RpbGUvMC8yMDAwNQAAAAAAAAD4YzAM.jpg" align="right"&gt;on the right.&amp;nbsp; It would seem to me that any icons they allow you to select from online should be available on the XBOX Live site.&lt;/p&gt; &lt;p&gt;2.&amp;nbsp; Points.&amp;nbsp; This was something my friend told me about last night.&amp;nbsp; Apparently if you choose to buy points in the store, they're sold in batches of &lt;a href="http://www.bestbuy.com/site/olspage.jsp?skuId=7530237&amp;amp;st=xbox+live+points&amp;amp;lp=1&amp;amp;type=product&amp;amp;cp=1&amp;amp;id=1127507946464" target="_blank"&gt;1600 or 4000&lt;/a&gt;&amp;nbsp;at about 80.04 points per dollar (USD).&amp;nbsp; If you buy them on the XBOX Live site or while you're in XBOX Live, they're sold in increments of 500/1000/2000/5000 at exactly 80 points per dollar.&amp;nbsp; So, if you discount tax and shipping/handling, it's actually cheaper to buy your points in a place like Best Buy instead of online.&amp;nbsp; &lt;/p&gt; &lt;p&gt;Like I said, though, those are just a few tiny tiny nitpicks.&amp;nbsp; Overall, the XBOX Live experience is really incredible!&amp;nbsp; It is truly much superior to the Wii and PS3 equivalent.&amp;nbsp; I can already tell that I'll be spending a lot more time playing my 360, which I guess is the whole point.&lt;/p&gt; &lt;p&gt;&lt;strong&gt;One last plug for Scott Hanselman, though.&amp;nbsp; He, &lt;a href="http://richhubbins.theclaussens.com/" target="_blank"&gt;Rich Claussen&lt;/a&gt; and &lt;a href="http://www.jasonmauer.com/" target="_blank"&gt;Jason Mauer&lt;/a&gt;&amp;nbsp;are hosting a Halo 3 tournament on October 20 as a benefit to raise money for Diabetes.&amp;nbsp; Since I'll be out that way for my MS Bootcamp during this time, I'm going to try and show-up.&amp;nbsp; But if you are in Vancouver, WA and would like to meet some MS guys and play Halo 3 on a 50 foot screen in Super Hi-Def, check out his &lt;/strong&gt;&lt;a href="http://feeds.feedburner.com/~r/ScottHanselman/~3/162541123/RaisingMoneyForDiabetesWithHalo3OnOct11.aspx" target="_blank"&gt;&lt;strong&gt;blog entry&lt;/strong&gt;&lt;/a&gt;&lt;strong&gt; and sign-up.&lt;/strong&gt;&amp;nbsp; &lt;/p&gt; &lt;p&gt;Enjoy!&lt;/p&gt; &lt;p&gt;&amp;nbsp;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:8f4a9f25-b056-4a53-8a78-d04319fd3742" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/XBOX%20360" rel="tag"&gt;XBOX 360&lt;/a&gt;, &lt;a href="http://technorati.com/tags/XBOX%20Live" rel="tag"&gt;XBOX Live&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Microsoft" rel="tag"&gt;Microsoft&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Hanselman" rel="tag"&gt;Hanselman&lt;/a&gt;&lt;/div&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=110" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Microsoft/default.aspx">Microsoft</category></item><item><title>The Road Not Taken</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2007/09/27/The-Road-Not-Taken.aspx</link><pubDate>Fri, 28 Sep 2007 06:33:06 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:109</guid><dc:creator>Greg</dc:creator><slash:comments>0</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/109.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=109</wfw:commentRss><description>&lt;blockquote&gt; &lt;p&gt;"...Somewhere ages and ages hence:&lt;br&gt;Two roads diverged in a wood, and I--&lt;br&gt;I took the one less traveled by,&lt;br&gt;And that has made all the difference."&lt;br&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; -- Robert Frost&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;You may have noticed that I've been more quiet than normal for the past month or two.&amp;nbsp; There is a reason for that.&amp;nbsp; I have decided to leave my current company of almost 4 years for another opportunity.&amp;nbsp; Starting Monday, October 8, 2007, I will be a full time employee of &lt;a href="http://www.microsoft.com/" target="_blank"&gt;Microsoft&lt;/a&gt;&amp;nbsp;on the Premier Field Engineering team!&amp;nbsp; If you're not familiar with this position at Microsoft, the description on the &lt;a href="http://www.microsoft.com/careers" target="_blank"&gt;Microsoft Careers&lt;/a&gt;&amp;nbsp;site states:&lt;/p&gt; &lt;blockquote&gt; &lt;p&gt;"The purpose of the Premier Field Engineer (PFE) position is to provide Microsoft customers with reliable technical solutions to the complex integration problems associated with business solutions built on the Microsoft platform. The PFE Team supports a diverse variety of technical solutions built with Microsoft technology and products Typical tasks performed in this role include specific problem isolation and correction, user and kernel mode debugging, conducting application design and supportability reviews, performance tuning, application stability consulting/troubleshooting, code reviews, and porting/migration assistance, configuration management, pre-rollout testing and general development consulting. The prospective PFE candidate should draw upon all resources at Microsoft, to advise and consult on the use of Microsoft technologies to avoid such problems in the future."&lt;/p&gt;&lt;/blockquote&gt; &lt;p&gt;This position immediately appealed to me because of its customer focus and technically challenging environment.&amp;nbsp; Plus, I get to help developers do their job better!&amp;nbsp; That alone&amp;nbsp;is a great high for me and I'm really looking forward to this new adventure!&amp;nbsp; From speaking with&amp;nbsp;members of my new&amp;nbsp;team and my future manager,&amp;nbsp;I can tell that this team is composed of incredibly intelligent folks and I am honored to be joining them.&lt;/p&gt; &lt;p&gt;All that said, though, this decision was far from easy for me to make.&amp;nbsp; I have had the distinct honor to work with some wonderful folks at my current company.&amp;nbsp; Plus, I was able to architect and design some great applications.&amp;nbsp; In the end, though, I knew that I had to take the road "less traveled by" and join a company that is constantly changing the world.&lt;/p&gt; &lt;p&gt;Here's a quick FAQ on the process and my new position:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;Do you have to move?&amp;nbsp; &lt;br&gt;&lt;br&gt;Nope.&amp;nbsp; I get to stay in good ol' Chicago for the time-being.&amp;nbsp; Even better, I get to work from home when I'm not at a client site.&lt;br&gt;&lt;/li&gt; &lt;li&gt;Wait, does that mean you don't get to go to Redmond at all?&amp;nbsp; &lt;br&gt;&lt;br&gt;Well, actually, I do.&amp;nbsp; For all folks in this arm of Microsoft's service group, your first three weeks are spent in Redmond at a bootcamp.&amp;nbsp; This is where I'll get wonderful things like my ID badge, laptop and learn all about the Service leg of MS.&lt;br&gt;&lt;/li&gt; &lt;li&gt;How did you find out about the job?&amp;nbsp; How did you apply, interview, etc.?&lt;br&gt;&lt;br&gt;Well, one of my friends sent me a link to the initial Job Details page saying that it might be a good fit for me.&amp;nbsp; After that, it was just a matter of signing up on the MS Careers site and submitting my resume.&amp;nbsp; This was the first time that I had ever applied to Microsoft before, so I wasn't entirely sure what to expect.&amp;nbsp; Pretty soon after I officially applied, though, I received an e-mail from an Recruiter over there and everything kind of snowballed from there.&amp;nbsp; All in all, the process took just over a month, from initial communication to the Offer stage.&amp;nbsp; I probably could have shortened that time-span, but I wanted to provide adequate time to prepare for each interview.&lt;br&gt;&lt;/li&gt; &lt;li&gt;What were the interviews like?&amp;nbsp; &lt;br&gt;&lt;br&gt;Well, my interview came in three stages:&lt;br&gt;&lt;br&gt;1.&amp;nbsp; HR phone interview.&amp;nbsp; This was there the Recruiter got to tell me about the position, the company, normal tasks, etc.&amp;nbsp; He also asked some fairly basic .NET questions.&lt;br&gt;&lt;br&gt;2.&amp;nbsp; Technical Screen.&amp;nbsp; This was an hour-long phone conversation with an incredibly sharp guy.&amp;nbsp; The questions were NOT easy, in-fact, this was probably the most difficult tech screen I have ever encountered.&amp;nbsp; They were simply not interested in how you develop a webpage, but instead asked some really difficult questions about garbage collection, the JIT compiler, and loads of .NET memory related questions.&amp;nbsp; We also got into some Windbg debugging and memory dumps.&amp;nbsp; Certainly not for the faint of heart.&lt;br&gt;&lt;br&gt;3.&amp;nbsp; In-Person Technical Interview and Managerial Interview.&amp;nbsp; This was about 2 hours long at one of the local MS offices and included a technical interview with 2 PFE's and a managerial type interview with 2 PFE Managers.&amp;nbsp; The technical interview included more of the same types of questions mentioned above but also included some best practice-type questions about Exception Handling and debugging issues.&amp;nbsp; The managerial interview included a lot of behavioral questions and also about how you manage difficult situations.&amp;nbsp; &lt;br&gt;&lt;/li&gt; &lt;li&gt;How did you prepare for them?&lt;br&gt;&lt;br&gt;I took a page from &lt;a href="http://jaysonknight.com/blog/archive/2007/04/25/interviewing-with-microsoft-and-landing-the-job-part-1-preparation-is-key.aspx" target="_blank"&gt;Jayson Knight's&lt;/a&gt;&amp;nbsp;blog and studied my little heart out.&amp;nbsp; My average was about 4 hours every night studying everything I could find and then some.&amp;nbsp; I re-read several books and tons of great blogs.&lt;br&gt;&lt;/li&gt; &lt;li&gt;What's going to happen to your blog?&lt;br&gt;&lt;br&gt;For the time being, I'm planning to keep it updated, but the focus may change a bit.&amp;nbsp; As my new position will include a lot of deep technical dives into some great technologies - the focus may be a bit more deeply technical in nature.&amp;nbsp; As I have always tried to keep the focus on simplifying development, though, expect more of those same types of entries.&lt;br&gt;&lt;/li&gt; &lt;li&gt;How did management at your current company take the news?&lt;br&gt;&lt;br&gt;Honestly, their reaction surprised me.&amp;nbsp; LOL...in a good way, I suppose.&amp;nbsp; They didn't even try to keep me.&amp;nbsp; As soon as I said "Microsoft" their eyes lit up and they offered their congratulations and gave me many hearty handshakes and hugs.&amp;nbsp; They all knew that this was a dream for me and it's nice to know that they were as happy for me as I was.&amp;nbsp; It was truly a testament to the wonderful and supportive folks that they employ.&lt;/li&gt;&lt;/ul&gt; &lt;p&gt;All in all, I feel very fortunate to have been given this incredible opportunity.&amp;nbsp; I can't wait to start my new adventure! &lt;/p&gt; &lt;p&gt;&lt;br&gt;&amp;nbsp;&lt;/p&gt; &lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:25d9645b-4b34-49bd-9016-edbdb234ef96" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/Working%20For%20Microsoft" rel="tag"&gt;Working For Microsoft&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Microsoft" rel="tag"&gt;Microsoft&lt;/a&gt;, &lt;a href="http://technorati.com/tags/.NET" rel="tag"&gt;.NET&lt;/a&gt;&lt;/div&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=109" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/Microsoft/default.aspx">Microsoft</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/.NET/default.aspx">.NET</category></item><item><title>SamuraiProgrammer.Web.UI - v0.5</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2007/09/27/SamuraiProgrammer.Web.UI-_2D00_-v0.5.aspx</link><pubDate>Fri, 28 Sep 2007 05:10:11 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:106</guid><dc:creator>Greg</dc:creator><slash:comments>0</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/106.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=106</wfw:commentRss><description>&lt;p&gt;One of my friends suggested that I should provide a download for all of the little code snippets, controls, etc. that I throw up on my blog so people don't have to constantly copy/paste into their IDE of choice.&amp;nbsp; &lt;/p&gt; &lt;p&gt;I thought about it and it sounded like a good idea but I think I'll do things a little bit different.&amp;nbsp; I fully intend to provide code downloads for each of my blog entries, but in addition to that, I'm going to expand upon them in a separate download.&amp;nbsp; The reason for this is that many times, I post very very simple solutions to common problems or issues.&amp;nbsp; I always leave it as an exercise for the reader to further enhance the simple code I provide.&amp;nbsp; &lt;/p&gt; &lt;p&gt;I like the way this works, but a lot of times I do the enhancing myself.&amp;nbsp; So, I might as well make that code available as well.&amp;nbsp; In this initial release (arbitrarily set as v0.5), I provide the following controls:&lt;/p&gt; &lt;ul&gt; &lt;li&gt;&lt;strong&gt;ValueCheckBox&lt;/strong&gt; - This was a control that I described &lt;a href="http://samuraiprogrammer.com/community/blogs/greg/archive/2007/08/21/GridView-Grouping-and-Checkbox-Lists.aspx" target="_blank"&gt;here&lt;/a&gt;&amp;nbsp;and is simply a CheckBox with an additional property (CheckBoxValue) that can be used in a grid/list/anywhere where you want to store an actual useful value for quick reference later.&lt;br&gt; &lt;li&gt;&lt;strong&gt;ConditionalDisplayPanel&lt;/strong&gt; - This was a control that I initially described &lt;a href="http://samuraiprogrammer.com/community/blogs/greg/archive/2007/09/11/Visibility-of-Fields-Within-FormView.aspx" target="_blank"&gt;here&lt;/a&gt;&amp;nbsp;and was a simple way to hide portions of a templated control from the user at runtime.&amp;nbsp; Since its first creation, though, I've actually enhanced this quite a bit.&amp;nbsp; Using&amp;nbsp;something similar to the GridView/SQLDataSource binding model, I have made this control a lot more flexible and extensible.&amp;nbsp; &lt;br&gt;&lt;br&gt;When you add this control to your page, you can specify in your XHTML a SuccessTemplate and a FailureTemplate.&amp;nbsp; Within each template, as with most templated controls, you can specify the controls/HTML to appear for each condition.&amp;nbsp; For example:&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;sp:ConditionalDisplayPanel&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;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="cdpTest"&lt;/span&gt; 
               &lt;span class="attr"&gt;EvaluationSourceId&lt;/span&gt;&lt;span class="kwrd"&gt;="cesCustomCheck"&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;FailureTemplate&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;asp:Label&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;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="lblFailure"&lt;/span&gt; 
                   &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Failure"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:Label&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;FailureTemplate&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;SuccessTemplate&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;asp:Label&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;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="lblSuccess"&lt;/span&gt; 
                   &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;="Success"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;asp:Label&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;SuccessTemplate&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;sp:ConditionalDisplayPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;li&gt;&lt;strong&gt;EvaluationSource &lt;/strong&gt;- In order to provide looser coupling between the uses of this control and the control itself, these simple controls provide a nice abstracted method of providing the condition for which the FailureTemplate and SuccessTemplate appear.&amp;nbsp; All EvaluationSource controls implement the IEvaluationSource interface which provides a method of evaluating success or failure.&amp;nbsp; The EvaluationSources included in this release are:&lt;br&gt;&lt;br&gt;&lt;strong&gt;RoleEvaluationSource:&lt;/strong&gt;&amp;nbsp; Provides a method to evaluate against a user's role membership.&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;sp:RoleEvaluationSource&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;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="resRoleCheck"&lt;/span&gt; 
                             &lt;span class="attr"&gt;RoleName&lt;/span&gt;&lt;span class="kwrd"&gt;="Test"&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;sp:RoleEvaluationSource&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;strong&gt;FieldEvaluationSource:&lt;/strong&gt;&amp;nbsp; Provides a method to evaluate against a a null or empty field value in a DataView.&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;sp:FieldEvaluationSource&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;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="fesAttributeName"&lt;/span&gt; 
                          &lt;span class="attr"&gt;FieldName&lt;/span&gt;&lt;span class="kwrd"&gt;="AttributeName"&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;sp:FieldEvaluationSource&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;strong&gt;CustomEvaluationSource:&lt;/strong&gt;&amp;nbsp; Allows the developer to specify their own logic to be evaluated.&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;sp:CustomEvaluationSource&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;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="cesCustomCheck"&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;sp:CustomEvaluationSource&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;Then, in the code behind, you simply handle the CustomValidate event raised in the control to provide your own logic to evaluate.&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;Protected&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; cesCustomCheck_CustomValidate( _
                            &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; source &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Object&lt;/span&gt;, _
                            &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; args &lt;span class="kwrd"&gt;As&lt;/span&gt; CustomValidateEventArgs) _
                                    &lt;span class="kwrd"&gt;Handles&lt;/span&gt; cesCustomCheck.CustomValidate
        args.IsValid = &lt;span class="kwrd"&gt;True&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;
&lt;li&gt;ControlPersister - This allows you to specify the values in one or more controls on a page and save them to a cookie when a certain event is raised by another control on the page.&amp;nbsp; In addition, the control will place the values back into the controls when the user next visits that page.&amp;nbsp; An example of the XHTML would be useful here perhaps:&lt;br&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;sp:ControlPersister&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;id&lt;/span&gt;&lt;span class="kwrd"&gt;="fpSearchFields"&lt;/span&gt; 
                     &lt;span class="attr"&gt;PersistenceKey&lt;/span&gt;&lt;span class="kwrd"&gt;="Search"&lt;/span&gt; 
                     &lt;span class="attr"&gt;PersistenceTypeName&lt;/span&gt;&lt;span class="kwrd"&gt;="cookie"&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;Sources&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;sp:ControlSource&lt;/span&gt; &lt;span class="attr"&gt;ControlName&lt;/span&gt;&lt;span class="kwrd"&gt;="txtSearchCriteria"&lt;/span&gt; 
                          &lt;span class="attr"&gt;ControlProperty&lt;/span&gt;&lt;span class="kwrd"&gt;="Text"&lt;/span&gt; 
                          &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="SearchCriteria1"&lt;/span&gt; 
                          &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&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;sp:ControlSource&lt;/span&gt; &lt;span class="attr"&gt;ControlName&lt;/span&gt;&lt;span class="kwrd"&gt;="ddlSearchCriteria2"&lt;/span&gt; 
                          &lt;span class="attr"&gt;ControlProperty&lt;/span&gt;&lt;span class="kwrd"&gt;="SelectedValue"&lt;/span&gt; 
                          &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="SearchCriteria2"&lt;/span&gt; 
                          &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="String"&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;sp:ControlSource&lt;/span&gt; &lt;span class="attr"&gt;ControlName&lt;/span&gt;&lt;span class="kwrd"&gt;="chkSearchCriteria3"&lt;/span&gt; 
                          &lt;span class="attr"&gt;ControlProperty&lt;/span&gt;&lt;span class="kwrd"&gt;="Checked"&lt;/span&gt; 
                          &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="SearchCriteria3"&lt;/span&gt; 
                          &lt;span class="attr"&gt;Type&lt;/span&gt;&lt;span class="kwrd"&gt;="Boolean"&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;Sources&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;SaveTriggers&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;sp:SaveTrigger&lt;/span&gt; &lt;span class="attr"&gt;ControlId&lt;/span&gt;&lt;span class="kwrd"&gt;="btnSearch"&lt;/span&gt; 
                        &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="SearchButton"&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;SaveTriggers&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;ResetTriggers&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;sp:ResetTrigger&lt;/span&gt; &lt;span class="attr"&gt;ControlId&lt;/span&gt;&lt;span class="kwrd"&gt;="btnReset"&lt;/span&gt; 
                         &lt;span class="attr"&gt;Name&lt;/span&gt;&lt;span class="kwrd"&gt;="ResetButton"&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;ResetTriggers&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;sp:ControlPersister&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;&lt;br&gt;&lt;strong&gt;Here is an explanation of each property on the base ControlPersister control:&lt;br&gt;&lt;/strong&gt;&lt;br&gt;PersistenceKey:&amp;nbsp; A string value representing the name of the cookie for this page.&amp;nbsp; This is useful if you have more than one ControlPersister on a page.&lt;br&gt;&lt;br&gt;PersistenceTypeName:&amp;nbsp; A string value representing the medium in which these values should be stored.&amp;nbsp; For this version of the control, only a "cookie" is available.&amp;nbsp; In future versions, you will be able to store the values in Session, Database or even using a File Based persistence model.&lt;br&gt;&lt;br&gt;&lt;strong&gt;Here is an explanation of each property on the ControlSource object:&lt;br&gt;&lt;/strong&gt;&lt;br&gt;ControlName:&amp;nbsp; A string value representing the name of the control to persist.&lt;br&gt;&lt;br&gt;ControlProperty:&amp;nbsp; A string value representing the property of the control from which you&amp;nbsp;should persist the values of the control.&amp;nbsp; This property is also used to *set* the value of the property on the initial page load.&lt;br&gt;&lt;br&gt;Name:&amp;nbsp; A string value representing the name of the instance of the ControlSource.&lt;br&gt;&lt;br&gt;Type:&amp;nbsp; A string value representing the type of data to be stored.&lt;br&gt;&lt;br&gt;&lt;strong&gt;Here is an explanation of each property on the SaveTrigger object:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;ControlId:&amp;nbsp; A string value representing the name of the control that would trigger the save operation of this control.&amp;nbsp; The control referenced here must implement the IButtonControl interface which exposes the Click event.&lt;br&gt;&lt;br&gt;Name:&amp;nbsp; A string value representing the name of the instance of the SaveTrigger.&lt;br&gt;&lt;br&gt;&lt;strong&gt;Here is an explanation of each property on the ResetTrigger object:&lt;br&gt;&lt;/strong&gt;&lt;br&gt;ControlId:&amp;nbsp; A string value representing the name of the control that would trigger the reset operation of this control.&amp;nbsp; When the user clicks this button, any values being persisted would be cleared and would not load the next time the page loaded.&amp;nbsp; The control referenced here must implement the IButtonControl interface which exposes the Click event.&lt;br&gt;&lt;br&gt;Name:&amp;nbsp; A string value representing the name of the instance of the ResetTrigger.&lt;br&gt;&lt;/li&gt;&lt;/ul&gt;
&lt;p&gt;I think that's it for this version of the SamuraiProgrammer.Web.UI.&amp;nbsp; You can download the assembly &lt;a href="http://samuraiprogrammer.com/community/Downloads/SamuraiProgrammer.Web.UI.v0.5/SamuraiProgrammer.Web.UI.zip" target="_blank"&gt;here&lt;/a&gt;.&amp;nbsp; I'll try to get some samples posted within the next week or so.&lt;/p&gt;
&lt;p&gt;Any questions or comments, please feel free to comment or contact me via the link on this page.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;br&gt;&lt;br&gt;&lt;br&gt;&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:18a24faa-07ee-4052-a8b0-c1e559b49393" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/ASP.NET%20Tips%20and%20Tricks" rel="tag"&gt;ASP.NET Tips and Tricks&lt;/a&gt;, &lt;a href="http://technorati.com/tags/ASP.NET" rel="tag"&gt;ASP.NET&lt;/a&gt;, &lt;a href="http://technorati.com/tags/.NET" rel="tag"&gt;.NET&lt;/a&gt;&lt;/div&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=106" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/ASP.NET+Tips+and+Tricks/default.aspx">ASP.NET Tips and Tricks</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/.NET/default.aspx">.NET</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/VB.NET/default.aspx">VB.NET</category></item><item><title>String Concatenation</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2007/09/16/String-Concatenation.aspx</link><pubDate>Mon, 17 Sep 2007 04:27:20 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:102</guid><dc:creator>Greg</dc:creator><slash:comments>0</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/102.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=102</wfw:commentRss><description>&lt;p&gt;This is an old topic, but as I work with developers more and more, I find that there is still some gray area on this topic.&lt;/p&gt; &lt;p&gt;Concatenating strings is probably one of the most comment tasks that most developers perform in their work-lives.&amp;nbsp; If you've ever done some searching around, though, you'll find that there are 2 main ways that people perform those concatenations:&lt;/p&gt; &lt;p&gt;First, you can use the "+" or the "&amp;amp;" operator with the native string object:&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;Sub&lt;/span&gt; ConcatWithStrings(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; max &lt;span class="kwrd"&gt;As&lt;/span&gt; Int32)
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt; = &lt;span class="str"&gt;""&lt;/span&gt;
        &lt;span class="kwrd"&gt;For&lt;/span&gt; i &lt;span class="kwrd"&gt;As&lt;/span&gt; Int32 = 0 &lt;span class="kwrd"&gt;To&lt;/span&gt; max
            value += i.ToString()
        &lt;span class="kwrd"&gt;Next&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;
&lt;p&gt;Second, you can use the System.Text.StringBuilder()&amp;nbsp;object to perform the concatenation:&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;Sub&lt;/span&gt; ConcatWithStringBuilder(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; max &lt;span class="kwrd"&gt;As&lt;/span&gt; Int32)
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; System.Text.StringBuilder()
        &lt;span class="kwrd"&gt;For&lt;/span&gt; i &lt;span class="kwrd"&gt;As&lt;/span&gt; Int32 = 0 &lt;span class="kwrd"&gt;To&lt;/span&gt; max
            value.Append(i.ToString())
        &lt;span class="kwrd"&gt;Next&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;
&lt;p&gt;So, which is better?&amp;nbsp; Well, if you do any Google'ing or Live Search'ing on the topic, you'll find some great articles on the topic.&amp;nbsp; &lt;a href="http://www.vbdotnetheaven.com/UploadFile/mahesh/StringBuilder04212005073651AM/StringBuilder.aspx" target="_blank"&gt;Mahesh Chand&lt;/a&gt;&amp;nbsp;has a great article, which I'll quote:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;"You can concatenate strings in two ways. First, traditional way of using string and adding the new string to an existing string. In the .NET Framework, this operation is costly. When you add a string to an existing string, the Framework copies both the existing and new&amp;nbsp; data to the memory, deletes the existing string, and reads data in a new string. This operation can be very time consuming in lengthy string&lt;br&gt;concatenation operations."&lt;/p&gt;&lt;/blockquote&gt;
&lt;p&gt;Now, I'm a big fan of short descriptions like the above, but I always find that without actually showing what is happening behind the scenes, you might lose some folks in the translation.&amp;nbsp; To illustrate what happens behind the scenes, I wrote a quick console application that uses the first code sample - and then took a memory dump using ADPlus to show what actually gets kept around in memory after the String level concatenation.&lt;/p&gt;
&lt;p&gt;I'm not going to go into a lot of detail on what I did to mine through the memory dump, but if you're interested in getting down to this detail on your own - I highly recommend the book &lt;a href="http://www.amazon.com/Debugging-Microsoft-NET-2-0-Applications/dp/0735622027/ref=sr_1_1/102-3226509-9232905?ie=UTF8&amp;amp;s=books&amp;amp;qid=1189998019&amp;amp;sr=8-1" target="_blank"&gt;Debugging Microsoft .NET 2.0 Applications&lt;/a&gt;.&amp;nbsp; After you read that great book, you should read &lt;a href="http://blogs.msdn.com/tess/" target="_blank"&gt;Tess's Great Blog&lt;/a&gt;&amp;nbsp;to get even more practice on this area.&lt;/p&gt;
&lt;p&gt;In any case, what was uncovered after the memory dump was that with the listing in the first example, there will be a separate String object placed into memory each time you perform a concatenation.&amp;nbsp; Here is an excerpt from that dump:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;#&lt;/u&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;u&gt;Size&lt;/u&gt; &lt;u&gt;Value&lt;/u&gt;&lt;/strong&gt; &lt;/p&gt;
&lt;p&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 28 "0123"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 28 "01234"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 32 "012345"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 32 "0123456"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 36 "01234567"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 36 "012345678"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 40 "0123456789"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 44 "012345678910"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 48 "01234567891011"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 52 "0123456789101112"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 56 "012345678910111213"&lt;br&gt;.....&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 124 "0123456789101112131415161718192021222324252627282930"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 128 "012345678910111213141516171819202122232425262728293031"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 132 "01234567891011121314151617181920212223242526272829303132"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 136 "0123456789101112131415161718192021222324252627282930313233"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 140 "012345678910111213141516171819202122232425262728293031323334"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 144 "01234567891011121314151617181920212223242526272829303132333435"&lt;br&gt;65&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 17940 ""012345678910111213141516171819202122232425262728293031323334353"&lt;/p&gt;
&lt;p&gt;First, the command I used outputs the first 65 characters or so within the String object.&amp;nbsp; This is why the last entry has a count of 65 instances.&amp;nbsp; In any case, as you can see, there is a separate copy of each string made into memory during each concatenation operation.&amp;nbsp; Ouch.&amp;nbsp; This can get expensive very quickly!&amp;nbsp; 
&lt;p&gt;Now what about the StringBuilder operation?
&lt;p&gt;&lt;strong&gt;&lt;u&gt;#&lt;/u&gt;&lt;/strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;strong&gt;&lt;u&gt;Size&lt;/u&gt;&lt;/strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;strong&gt;&lt;u&gt;Value&lt;/u&gt;&lt;/strong&gt;
&lt;p&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;52&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;"0123456789101112"&lt;br&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;84&amp;nbsp;&amp;nbsp;&amp;nbsp; "01234567891011121314151617181920"&lt;br&gt;3&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;956&amp;nbsp; "012345678910111213141516171819202122232425262728293031323334353"
&lt;p&gt;Gee, that seems a lot simpler - but if you're paying attention, you'll notice that there are&amp;nbsp;a few other&amp;nbsp;instances of this lengthy string in memory.&amp;nbsp; Any ideas why?&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Well, this appears to be my bug.&amp;nbsp; When you instantiate a System.Text.StringBuilder object, one of the constructors allows for a integer parameter called "Capacity".&amp;nbsp; If you do not specify an initial capacity, the noargs constructor defaults to "&amp;amp;H10" - which is 16 characters.&amp;nbsp; If, during your string operations, you exceed that 16 character capacity, the StringBuilder will create a new new string with a capacity of 32 (16 * 2) characters.&amp;nbsp; The next time, you perform an operation that needs more than 32 characters, the StringBuilder will double the capacity again - this time to 64 characters.&amp;nbsp; This will continue to happen over and over again as you continually append more characters to the StringBuilder object.&lt;/p&gt;
&lt;p&gt;So, what does this mean?&amp;nbsp; Well, it means that we're still not achieving the maximum efficiency here.&amp;nbsp; If we want to build a String like this - without creating extra instances of the base string object - even when using a StringBuilder object, you should specify a capacity in the constructor.&amp;nbsp; To prove this hypothesis, we can&amp;nbsp;rewrite the&amp;nbsp;second code listing to be:&lt;/p&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;Sub&lt;/span&gt; ConcatWithStringBuilder(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; max &lt;span class="kwrd"&gt;As&lt;/span&gt; Int32)
        &lt;span class="kwrd"&gt;Dim&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;New&lt;/span&gt; System.Text.StringBuilder(193)
        &lt;span class="kwrd"&gt;For&lt;/span&gt; i &lt;span class="kwrd"&gt;As&lt;/span&gt; Int32 = 0 &lt;span class="kwrd"&gt;To&lt;/span&gt; max
            value.Append(i.ToString())
        &lt;span class="kwrd"&gt;Next&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; Sub&lt;/pre&gt;
&lt;p&gt;Now, when we take a memory dump and look for the String objects for the above loop:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;u&gt;#&lt;/u&gt;&lt;/strong&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;strong&gt;&lt;u&gt;Size&lt;/u&gt;&lt;/strong&gt;&amp;nbsp; &lt;strong&gt;&lt;u&gt;Value&lt;/u&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;1&amp;nbsp;&amp;nbsp;&amp;nbsp;404&amp;nbsp;&amp;nbsp;"012345678910111213141516171819202122232425262728293031323334353"&lt;/p&gt;
&lt;p&gt;We see that there is only one&amp;nbsp;instance of the String object in memory.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Moral of the story?&amp;nbsp; Even when using the StringBuilder object, if you know the final string is going to be lengthy, you should set an initial capacity to most efficiently perform your string concatenations.&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:61511a5f-5fd1-401a-8f1e-3547f17d7631" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/.NET" rel="tag"&gt;.NET&lt;/a&gt;, &lt;a href="http://technorati.com/tags/VB.NET" rel="tag"&gt;VB.NET&lt;/a&gt;, &lt;a href="http://technorati.com/tags/String%20Concatenation" rel="tag"&gt;String Concatenation&lt;/a&gt;, &lt;a href="http://technorati.com/tags/Tips%20and%20Tricks" rel="tag"&gt;Tips and Tricks&lt;/a&gt;&lt;/div&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=102" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/ASP.NET+Tips+and+Tricks/default.aspx">ASP.NET Tips and Tricks</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/.NET/default.aspx">.NET</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/VB.NET/default.aspx">VB.NET</category></item><item><title>Visibility of Fields Within FormView</title><link>http://samuraiprogrammer.com/community/blogs/greg/archive/2007/09/11/Visibility-of-Fields-Within-FormView.aspx</link><pubDate>Wed, 12 Sep 2007 05:51:27 GMT</pubDate><guid isPermaLink="false">e901b89f-4ea5-4b5f-bda4-a5b1e1ca6e85:101</guid><dc:creator>Greg</dc:creator><slash:comments>1</slash:comments><comments>http://samuraiprogrammer.com/community/blogs/greg/comments/101.aspx</comments><wfw:commentRss>http://samuraiprogrammer.com/community/blogs/greg/commentrss.aspx?PostID=101</wfw:commentRss><description>&lt;p&gt;A quick trick that I'm sure many of you know.&amp;nbsp; Suppose you had a FormView on a page bound to a datasource.&amp;nbsp; Within that FormView, you have several fields that may or may not contain data.&amp;nbsp; Now, suppose that for whatever reason, your sponsor would like you to make a control and its label disappear if the corresponding field contained no data.&amp;nbsp; What are the different ways to achieve this simple requirement?&lt;/p&gt; &lt;ol&gt; &lt;li&gt;You can handle the DataBinding event of the FormView and set the visibility of controls in the depending upon a field's value.&amp;nbsp;  &lt;li&gt;You can set the Visible property of the controls based upon a method defined in your page's code behind.&amp;nbsp; Possibly something like this:&lt;/li&gt;&lt;/ol&gt;&lt;pre class="csharpcode"&gt;    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Function&lt;/span&gt; ShouldDisplay(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; text &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Object&lt;/span&gt;) _
                                                    &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Boolean&lt;/span&gt;
        &lt;span class="kwrd"&gt;If&lt;/span&gt; text &lt;span class="kwrd"&gt;Is&lt;/span&gt; DBNull.Value &lt;span class="kwrd"&gt;OrElse&lt;/span&gt; _
            &lt;span class="kwrd"&gt;String&lt;/span&gt;.IsNullOrEmpty(text.ToString.Trim) &lt;span class="kwrd"&gt;Then&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; &lt;span class="kwrd"&gt;False&lt;/span&gt;
        &lt;span class="kwrd"&gt;Else&lt;/span&gt;
            &lt;span class="kwrd"&gt;Return&lt;/span&gt; &lt;span class="kwrd"&gt;True&lt;/span&gt;
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;
    &lt;span class="kwrd"&gt;End&lt;/span&gt; Function&lt;/pre&gt;
&lt;p&gt;And then you can set the visible property of the controls like this:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Label&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="Label"&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;='&amp;lt;%# ShouldDisplay(Eval("Description")) %&amp;gt;'&lt;/span&gt; 
           &lt;span class="attr"&gt;Text&lt;/span&gt;&lt;span class="kwrd"&gt;='&amp;lt;%# (Eval("Description")) %&amp;gt;'&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;asp:Label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;3.&amp;nbsp; You can combine #1 and #2 and encapsulate this into something a little reusable.&lt;/p&gt;
&lt;p&gt;Enter the ConditionalDisplayPanel.&amp;nbsp; This is something very simple which has potential to save you time over and over again.&amp;nbsp; To show how it works, here is the definition of a simple FormView control before applying the logic from above:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:FormView&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="FormView2"&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;DataKeyNames&lt;/span&gt;&lt;span class="kwrd"&gt;="AttributeId"&lt;/span&gt; 
              &lt;span class="attr"&gt;DataSourceID&lt;/span&gt;&lt;span class="kwrd"&gt;="SqlDataSource1"&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;ItemTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        AttributeId:
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Label&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="AttributeIdLabel"&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;Text&lt;/span&gt;&lt;span class="kwrd"&gt;='&amp;lt;%# Eval("AttributeId") %&amp;gt;'&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;asp:Label&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;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;      
       AttributeName:
       &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Label&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="AttributeNameLabel"&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;Text&lt;/span&gt;&lt;span class="kwrd"&gt;='&amp;lt;%# Bind("AttributeName") %&amp;gt;'&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;asp:Label&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;br&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;ItemTemplate&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;asp:FormView&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Now, in this example, suppose you don't want to display the AttributeName text or Label if there is no data in the AttributeName field in the datasource.&amp;nbsp; In that case, you simply wrap the AttributeName HTML with the ConditionalDisplayPanel like so:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:FormView&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="FormView1"&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;DataKeyNames&lt;/span&gt;&lt;span class="kwrd"&gt;="AttributeId"&lt;/span&gt; 
              &lt;span class="attr"&gt;DataSourceID&lt;/span&gt;&lt;span class="kwrd"&gt;="SqlDataSource1"&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;ItemTemplate&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;
        AttributeId:
        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Label&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="AttributeIdLabel"&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;Text&lt;/span&gt;&lt;span class="kwrd"&gt;='&amp;lt;%# Eval("AttributeId") %&amp;gt;'&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;asp:Label&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt; 
&lt;strong&gt;&lt;em&gt;        &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;sp:ConditionalDisplayPanel&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;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="pnlAttributeName"&lt;/span&gt; 
                                    &lt;span class="attr"&gt;FieldName&lt;/span&gt;&lt;span class="kwrd"&gt;="AttributeName"&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/em&gt;&lt;/strong&gt;        
            AttributeName:
            &lt;span class="kwrd"&gt;&amp;lt;&lt;/span&gt;&lt;span class="html"&gt;asp:Label&lt;/span&gt; &lt;span class="attr"&gt;ID&lt;/span&gt;&lt;span class="kwrd"&gt;="AttributeNameLabel"&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;Text&lt;/span&gt;&lt;span class="kwrd"&gt;='&amp;lt;%# Bind("AttributeName") %&amp;gt;'&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;asp:Label&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;br&lt;/span&gt; &lt;span class="kwrd"&gt;/&amp;gt;&lt;/span&gt;
        &lt;strong&gt;&lt;em&gt;&lt;font color="#008000"&gt;&lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;sp:ConditionalDisplayPanel&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/font&gt;&lt;/em&gt;&lt;/strong&gt;   
    &lt;span class="kwrd"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="html"&gt;ItemTemplate&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;asp:FormView&lt;/span&gt;&lt;span class="kwrd"&gt;&amp;gt;&lt;/span&gt;&lt;/pre&gt;
&lt;p&gt;Please note the FieldName property on the ConditionalDisplayPanel.&amp;nbsp; This property tells the ConditionalDisplayPanel which field should be evaluated to determine if the contents of the control should be displayed.&amp;nbsp; At runtime during the binding of the controls in the FormView, the ConditionalDisplayPanel will evaluate the contents of that particular Field and if there is any data in the field, it will display the AttributeName HTML.&amp;nbsp; If not, then the opposite will happen.&lt;/p&gt;
&lt;p&gt;Simple, no?&amp;nbsp; &lt;/p&gt;
&lt;p&gt;Well, how does this work?&amp;nbsp; Actually, the ConditionalDisplayPanel was relatively simple to construct.&amp;nbsp; Here is the full class:&lt;/p&gt;&lt;pre class="csharpcode"&gt;&lt;span class="kwrd"&gt;Namespace&lt;/span&gt; WebControls
    &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt; ConditionalDisplayPanel
        &lt;span class="kwrd"&gt;Inherits&lt;/span&gt; Panel

        &lt;span class="kwrd"&gt;Private&lt;/span&gt; _fieldName &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;

        &lt;span class="kwrd"&gt;Public&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt; FieldName() &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;
            &lt;span class="kwrd"&gt;Get&lt;/span&gt;
                &lt;span class="kwrd"&gt;Return&lt;/span&gt; _fieldName
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Get&lt;/span&gt;
            &lt;span class="kwrd"&gt;Set&lt;/span&gt;(&lt;span class="kwrd"&gt;ByVal&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;String&lt;/span&gt;)
                _fieldName = value
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Set&lt;/span&gt;
        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Property&lt;/span&gt;

        &lt;span class="kwrd"&gt;Private&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt; ConditionalPanel_DataBinding( _&lt;br&gt;                                               &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; sender &lt;span class="kwrd"&gt;As&lt;/span&gt; _&lt;br&gt;                                                   &lt;span class="kwrd"&gt;Object&lt;/span&gt;, _
                                               &lt;span class="kwrd"&gt;ByVal&lt;/span&gt; e &lt;span class="kwrd"&gt;As&lt;/span&gt; _&lt;br&gt;                                                   System.EventArgs) _
                                               &lt;span class="kwrd"&gt;Handles&lt;/span&gt; &lt;span class="kwrd"&gt;Me&lt;/span&gt;.DataBinding
            &lt;span class="rem"&gt;'// The naming container here (in a bindable context) &lt;/span&gt;
            &lt;span class="rem"&gt;'// implements the IDataItemContainer&lt;/span&gt;
            &lt;span class="kwrd"&gt;Dim&lt;/span&gt; container &lt;span class="kwrd"&gt;As&lt;/span&gt; IDataItemContainer = _
                        &lt;span class="kwrd"&gt;DirectCast&lt;/span&gt;(&lt;span class="kwrd"&gt;Me&lt;/span&gt;.NamingContainer, _&lt;br&gt;                                         IDataItemContainer)

            &lt;span class="rem"&gt;'// Using the property of that container, &lt;/span&gt;
            &lt;span class="rem"&gt;'// DataItem, you can get at the DataRowView being bound.&lt;/span&gt;
            &lt;span class="kwrd"&gt;Dim&lt;/span&gt; row &lt;span class="kwrd"&gt;As&lt;/span&gt; Data.DataRowView = _
                        &lt;span class="kwrd"&gt;DirectCast&lt;/span&gt;(container.DataItem, _&lt;br&gt;                                          Data.DataRowView)

            &lt;span class="rem"&gt;'// Retrieve the value from the row.&lt;/span&gt;
            &lt;span class="kwrd"&gt;Dim&lt;/span&gt; value &lt;span class="kwrd"&gt;As&lt;/span&gt; &lt;span class="kwrd"&gt;Object&lt;/span&gt; = row(&lt;span class="kwrd"&gt;Me&lt;/span&gt;.FieldName)

            &lt;span class="rem"&gt;'// Perform the comparison and set the Visible &lt;br&gt;            '// Property Accordingly.&lt;/span&gt;
            &lt;span class="kwrd"&gt;If&lt;/span&gt; value &lt;span class="kwrd"&gt;Is&lt;/span&gt; DBNull.Value &lt;span class="kwrd"&gt;OrElse&lt;/span&gt; _
                        &lt;span class="kwrd"&gt;String&lt;/span&gt;.IsNullOrEmpty(value.ToString.Trim) &lt;span class="kwrd"&gt;Then&lt;/span&gt;
                &lt;span class="kwrd"&gt;Me&lt;/span&gt;.Visible = &lt;span class="kwrd"&gt;False&lt;/span&gt;
            &lt;span class="kwrd"&gt;Else&lt;/span&gt;
                &lt;span class="kwrd"&gt;Me&lt;/span&gt;.Visible = &lt;span class="kwrd"&gt;True&lt;/span&gt;
            &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;If&lt;/span&gt;

        &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Sub&lt;/span&gt;

    &lt;span class="kwrd"&gt;End&lt;/span&gt; &lt;span class="kwrd"&gt;Class&lt;/span&gt;
&lt;span class="kwrd"&gt;End&lt;/span&gt; Namespace&lt;/pre&gt;By using this simple control, you can control this situation in one place for your entire application.&amp;nbsp; It could obviously be enhanced to perform many other checks, but as this was a 15 minute thing, I thought it would be best to keep it simple. 
&lt;p&gt;I hope this helps!&lt;/p&gt;
&lt;p&gt;Enjoy!&lt;/p&gt;
&lt;div class="wlWriterSmartContent" id="0767317B-992E-4b12-91E0-4F059A8CECA8:269467a5-a938-4799-a7de-76558f1e88a1" style="padding-right:0px;display:inline;padding-left:0px;padding-bottom:0px;margin:0px;padding-top:0px;"&gt;Technorati Tags: &lt;a href="http://technorati.com/tags/VB.NET" rel="tag"&gt;VB.NET&lt;/a&gt;, &lt;a href="http://technorati.com/tags/ASP.NET%20Tips%20and%20Tricks" rel="tag"&gt;ASP.NET Tips and Tricks&lt;/a&gt;, &lt;a href="http://technorati.com/tags/ASP.NET" rel="tag"&gt;ASP.NET&lt;/a&gt;&lt;/div&gt;&lt;img src="http://samuraiprogrammer.com/community/aggbug.aspx?PostID=101" width="1" height="1"&gt;</description><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/ASP.NET+Tips+and+Tricks/default.aspx">ASP.NET Tips and Tricks</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/ASP.NET/default.aspx">ASP.NET</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/.NET/default.aspx">.NET</category><category domain="http://samuraiprogrammer.com/community/blogs/greg/archive/tags/VB.NET/default.aspx">VB.NET</category></item></channel></rss>