<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:pingback="http://madskills.com/public/xml/rss/module/pingback/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:dc="http://purl.org/dc/elements/1.1/" version="2.0">
  <channel>
    <title>Dot Net Technologies -- MS Tech talk and more - C#</title>
    <link>http://www.dotnettechnologies.com/</link>
    <description>Creating Solutions with Microsoft's .Net Technologies</description>
    <language>en-us</language>
    <copyright>© Copyright 2010 </copyright>
    <lastBuildDate>Thu, 05 Aug 2010 01:39:30 GMT</lastBuildDate>
    <generator>newtelligence dasBlog 2.3.9074.18820</generator>
    <managingEditor>daryl@rubiconcomputing.com</managingEditor>
    <webMaster>daryl@rubiconcomputing.com</webMaster>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=7d2750ec-eecd-4aac-ac3b-0f09da032d74</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,7d2750ec-eecd-4aac-ac3b-0f09da032d74.aspx</pingback:target>
      <dc:creator>Daryl</dc:creator>
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,7d2750ec-eecd-4aac-ac3b-0f09da032d74.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=7d2750ec-eecd-4aac-ac3b-0f09da032d74</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">Ever need to HTML Encode a string? This
useful extension method will do it for you:<pre><span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
&lt;summary&gt;</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
Extension method to HTML encode any string characters with ASCII &gt; 127</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
&lt;/summary&gt;</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
&lt;param name="str"&gt;string to be encoded&lt;/param&gt;</span><span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;">///
&lt;returns&gt;Encoded string&lt;/returns&gt;</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">public</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">static</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> ToHtml(<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">this</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span> str)
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">return</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">string</span>.Join(<span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">""</span>,
str.ToCharArray().Select(c =&gt; (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>)c
&gt; 127 ? <span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">"&amp;#"</span><span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span>)c <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">+</span><span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;">";"</span> :
c.ToString()).ToArray()); } </span></pre><br /><br /><br /><br /><br /><p></p><img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=7d2750ec-eecd-4aac-ac3b-0f09da032d74" /></body>
      <title>Tip of the Day: An extension method to HTML encode a string</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,7d2750ec-eecd-4aac-ac3b-0f09da032d74.aspx</guid>
      <link>http://www.dotnettechnologies.com/2010/08/05/TipOfTheDayAnExtensionMethodToHTMLEncodeAString.aspx</link>
      <pubDate>Thu, 05 Aug 2010 01:39:30 GMT</pubDate>
      <description>Ever need to HTML Encode a string? This useful extension method will do it for you:&lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
Extension method to HTML encode any string characters with ASCII &amp;gt; 127&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;/summary&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;param name="str"&amp;gt;string to be encoded&amp;lt;/param&amp;gt;&lt;/span&gt; &lt;span style="color: Green; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;///
&amp;lt;returns&amp;gt;Encoded string&amp;lt;/returns&amp;gt;&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;public&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;static&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; ToHtml(&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;this&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt; str)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;return&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;string&lt;/span&gt;.Join(&lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;""&lt;/span&gt;,
str.ToCharArray().Select(c =&amp;gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;)c
&amp;gt; 127 ? &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;"&amp;amp;#"&lt;/span&gt; &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt;)c &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;+&lt;/span&gt; &lt;span style="color: rgb(102, 102, 102); background-color: rgb(228, 228, 228); font-family: Courier New; font-size: 11px;"&gt;";"&lt;/span&gt; :
c.ToString()).ToArray()); } &lt;/span&gt;&lt;/pre&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=7d2750ec-eecd-4aac-ac3b-0f09da032d74" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,7d2750ec-eecd-4aac-ac3b-0f09da032d74.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=1b1a5647-ec5f-4480-9708-f51c7d6e1f05</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,1b1a5647-ec5f-4480-9708-f51c7d6e1f05.aspx</pingback:target>
      <dc:creator>Daryl</dc:creator>
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,1b1a5647-ec5f-4480-9708-f51c7d6e1f05.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=1b1a5647-ec5f-4480-9708-f51c7d6e1f05</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today I was setting up a new template, and I needed to look at the unique constraints
as part of my task.
</p>
        <p>
The following CodeSmith script will load the columns that have unique constraints
(but not the primary key) into an ArrayList.
</p>
        <code>
          <pre>
            <span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;">ArrayList
uniqueColumns <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span><span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">new</span> ArrayList(); <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">for</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> i <span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;">=</span> 0;
i &lt; SourceTable.Indexes.Count; i++) { <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (SourceTable.Indexes[i].IsUnique)
{ <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">for</span> (<span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">int</span> y=0;
y &lt; SourceTable.Indexes[i].MemberColumns.Count; y++) { <span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;">if</span> (!SourceTable.Indexes[i].MemberColumns[y].IsPrimaryKeyMember)
uniqueColumns.Add(SourceTable.Indexes[i].MemberColumns[y].Name); } } }</span>
          </pre>
        </code>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=1b1a5647-ec5f-4480-9708-f51c7d6e1f05" />
      </body>
      <title>Tip of the Day: CodeSmith - Retrieve the unique columns from a table</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,1b1a5647-ec5f-4480-9708-f51c7d6e1f05.aspx</guid>
      <link>http://www.dotnettechnologies.com/2010/08/03/TipOfTheDayCodeSmithRetrieveTheUniqueColumnsFromATable.aspx</link>
      <pubDate>Tue, 03 Aug 2010 05:13:07 GMT</pubDate>
      <description>&lt;p&gt;
Today I was setting up a new template, and I needed to look at the unique constraints
as part of my task.
&lt;/p&gt;
&lt;p&gt;
The following CodeSmith script will load the columns that have unique constraints
(but not the primary key) into an ArrayList.
&lt;/p&gt;
&lt;code&gt; &lt;pre&gt;&lt;span style="color: Black; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;ArrayList
uniqueColumns &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;new&lt;/span&gt; ArrayList(); &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;for&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; i &lt;span style="color: Red; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;=&lt;/span&gt; 0;
i &amp;lt; SourceTable.Indexes.Count; i++) { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (SourceTable.Indexes[i].IsUnique)
{ &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;for&lt;/span&gt; (&lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;int&lt;/span&gt; y=0;
y &amp;lt; SourceTable.Indexes[i].MemberColumns.Count; y++) { &lt;span style="color: Blue; background-color: transparent; font-family: Courier New; font-size: 11px;"&gt;if&lt;/span&gt; (!SourceTable.Indexes[i].MemberColumns[y].IsPrimaryKeyMember)
uniqueColumns.Add(SourceTable.Indexes[i].MemberColumns[y].Name); } } }&lt;/span&gt;&lt;/pre&gt;&lt;/code&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=1b1a5647-ec5f-4480-9708-f51c7d6e1f05" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,1b1a5647-ec5f-4480-9708-f51c7d6e1f05.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=99a406e0-5f34-4f29-9651-6b6b9fcd0545</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,99a406e0-5f34-4f29-9651-6b6b9fcd0545.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,99a406e0-5f34-4f29-9651-6b6b9fcd0545.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=99a406e0-5f34-4f29-9651-6b6b9fcd0545</wfw:commentRss>
      <title>Tip of the Day: Manipulating ASP.Net validators client side</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,99a406e0-5f34-4f29-9651-6b6b9fcd0545.aspx</guid>
      <link>http://www.dotnettechnologies.com/2010/03/02/TipOfTheDayManipulatingASPNetValidatorsClientSide.aspx</link>
      <pubDate>Tue, 02 Mar 2010 04:29:40 GMT</pubDate>
      <description>&lt;p&gt;
This tip will show how to get a reference to a validator using client-side script,
check the valid state of the validator control, and set a validator control active
state client-side as well.
&lt;/p&gt;
&lt;p&gt;
I ran across a situation today to validate two dates (txtStartDate, txtEndDate) with
the following criteria:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
txtStartDate is required (use RequiredFieldValidator)&lt;/li&gt;
&lt;li&gt;
txtEndDate is required (use RequiredFieldValidator)&lt;/li&gt;
&lt;li&gt;
txtStartDate must be a valid date (use RegularExpressionValidator)&lt;/li&gt;
&lt;li&gt;
txtEndDate must be a valid date (use RegularExpressionValidator)&lt;/li&gt;
&lt;li&gt;
txtStartDate must occur before txtEndDate (use CompareValidator)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
Granted, I could write client script for doing this in one fell swoop, but I inherited
this page and these validators were already there, and I was just there to fix a bug.
&lt;/p&gt;
&lt;p&gt;
The QA person logged an issue like this: 
&lt;/p&gt;
&lt;p&gt;
txtStateDate value – 11/1/2009
&lt;/p&gt;
&lt;p&gt;
txtEndDate value – 11/31/2009 (invalid date)
&lt;/p&gt;
&lt;p&gt;
The “bug” was that in this case txtEndDate is not a valid date. The RegularExpression
Validator correctly caught this, but the Compare Validator still fired, indicating
a second error. The QA person felt that we should only display an “invalid date” error. 
&lt;/p&gt;
&lt;p&gt;
My options were to strip out the RegularExpressionValidator and CompareValidator and
use a CustomValidator and write some javascript. But really all I needed to do is
disable the CompareValidator if the txtBeginDate or txtEndDate is not a valid date.
&lt;/p&gt;
&lt;p&gt;
It took some doing, but I came up with a simple solution. I added a CustomValidator,
and called a client side function called ControlEndDateValidators(). You need one
for each date input.
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&amp;lt;asp:CustomValidator
ID=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"valEndDateCheck"&lt;/span&gt; runat=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"server"&lt;/span&gt; ControlToValidate=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"txEndDate"&lt;/span&gt; ClientValidationFunction=&lt;span style="FONT-SIZE: 11px; COLOR: #666666; FONT-FAMILY: Courier New; BACKGROUND-COLOR: #e4e4e4"&gt;"ControlEndDateValidators"&lt;/span&gt; /&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
The function obtains a reference to the validators, and the compare validator is only
made active if the data is valid per the RegularExpressionValidators. To check and
see if a validator is valid client-side, check the isvalid property for true/false.
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: blue; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&amp;lt;&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: #a31515; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;script&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;font color=#000000&gt; &lt;/font&gt;&lt;span style="COLOR: red"&gt;language&lt;/span&gt;&lt;span style="COLOR: blue"&gt;&lt;?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" /&gt;="javascript"&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;function&lt;/span&gt;&lt;font color=#000000&gt; ControlEndDateValidators(source,
arguments) 
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt;&lt;font color=#000000&gt; regExpValidatorEndDate
= document.getElementById(&lt;/font&gt;&lt;span style="COLOR: #a31515"&gt;"&amp;lt;%=valEndDate.ClientID
%&amp;gt;"&lt;/span&gt;&lt;font color=#000000&gt;);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt;&lt;font color=#000000&gt; regExpValidatorBeginDate
= document.getElementById(&lt;/font&gt;&lt;span style="COLOR: #a31515"&gt;"&amp;lt;%=valStartDate.ClientID
%&amp;gt;"&lt;/span&gt;&lt;font color=#000000&gt;);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;var&lt;/span&gt;&lt;font color=#000000&gt; compareValidator
= document.getElementById(&lt;/font&gt;&lt;span style="COLOR: #a31515"&gt;"&amp;lt;%=valDate.ClientID
%&amp;gt;"&lt;/span&gt;&lt;font color=#000000&gt;);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ValidationEnable(compareValidator,
(regExpValidatorBeginDate.isvalid) &amp;amp;&amp;amp; (regExpValidatorEndDate.isvalid));&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;
&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;span style="mso-spacerun: yes"&gt;&lt;font color=#000000&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;/span&gt;&lt;span style="COLOR: blue"&gt;function&lt;/span&gt;&lt;font color=#000000&gt; ValidationEnable(val,
enable)&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;{&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;val.enabled
= (enable != &lt;/font&gt;&lt;span style="COLOR: blue"&gt;false&lt;/span&gt;&lt;font color=#000000&gt;);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ValidatorValidate(val);&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;ValidatorUpdateIsValid();&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt; LINE-HEIGHT: normal; mso-layout-grid-align: none"&gt;
&lt;span style="FONT-SIZE: 10pt; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&lt;font color=#000000&gt;&lt;span style="mso-spacerun: yes"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;}&lt;o:p&gt;&lt;/o:p&gt;
&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 10pt"&gt;
&lt;span style="FONT-SIZE: 10pt; COLOR: blue; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&amp;lt;/&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: #a31515; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;script&lt;/span&gt;&lt;span style="FONT-SIZE: 10pt; COLOR: blue; LINE-HEIGHT: 115%; FONT-FAMILY: 'Courier New'; mso-no-proof: yes"&gt;&amp;gt;&lt;o:p&gt;&lt;/o:p&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;br&gt;
Again, we could write client-script code perform all this validation, but sometimes
time is of the essence. Using the functions above, we have shown how to get a reference
to a validator client-side,&amp;nbsp; check whether it is valid, and finally enable a
validator on the client-side.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=99a406e0-5f34-4f29-9651-6b6b9fcd0545" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,99a406e0-5f34-4f29-9651-6b6b9fcd0545.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=11d51691-b09f-4422-aaa5-15a7bf2b628c</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,11d51691-b09f-4422-aaa5-15a7bf2b628c.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,11d51691-b09f-4422-aaa5-15a7bf2b628c.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=11d51691-b09f-4422-aaa5-15a7bf2b628c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When starting a project, I always recommend inheriting objects from a base object,
regardless of whether you know you'll need it or not. Usually, they will contain common
functionality like error handling, debugging or other common methods which you'll
use over and over.
</p>
        <p>
In WinForms, however, this can cause a problem if you make the base form an abstract
class (another thing I recommend).  For example, take this simple form:
</p>
        <p>
 
</p>
        <p>
          <img src="http://www.dotnettechnologies.com/content/binary/FormExample.png" border="0" />
        </p>
        <p>
Now let's say I decide to derive this form from an abstract base class, which I will
call BaseForm:
</p>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">    5</span> <span style="COLOR: blue">using</span> System.Windows.Forms;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">    6</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">    7</span> <span style="COLOR: blue">namespace</span> TestForm
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">    8</span> {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">    9</span>     <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">BaseForm</span> : <span style="COLOR: #2b91af">Form</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   10</span>     {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   11</span>         <span style="COLOR: blue">protected</span><span style="COLOR: blue">void</span> SomeCommonMethod()
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   12</span>        
{
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   13</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   14</span>        
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   15</span>     }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   16</span> }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">When I go to edit the UI again, I see this, and it scares
the heck out of me (looks scarier in VS2005)....</font>
          </p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">
            </font>
            <img src="http://www.dotnettechnologies.com/content/binary/ErrorPage1.png" border="0" />
          </p>
          <p style="MARGIN: 0px">
            <!--EndFragment-->
          </p>
        </div>
        <p>
What this is telling you is that it can't render an abstract class BaseForm. So while
you are creating the application, you might remove the abstract identifier
from UI related base classes (with a note that they should be inherited from, not
used, as well as a /TODO marker to make sure you mark it as abstract before deployment). 
</p>
        <p>
Doing this will allow you to inherit from a base class while at the same time edit
the UI.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=11d51691-b09f-4422-aaa5-15a7bf2b628c" />
      </body>
      <title>Tip of the Day: Winform: Displaying the form derived from a base class</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,11d51691-b09f-4422-aaa5-15a7bf2b628c.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/10/14/TipOfTheDayWinformDisplayingTheFormDerivedFromABaseClass.aspx</link>
      <pubDate>Wed, 14 Oct 2009 05:27:16 GMT</pubDate>
      <description>&lt;p&gt;
When starting a project, I always recommend inheriting objects from a base object,
regardless of whether you know you'll need it or not. Usually, they will contain common
functionality like error handling, debugging or other common methods which you'll
use over and over.
&lt;/p&gt;
&lt;p&gt;
In WinForms, however, this can cause a problem if you make the base form an abstract
class (another thing I recommend).&amp;nbsp; For example, take this simple form:
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.dotnettechnologies.com/content/binary/FormExample.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
Now let's say I decide to derive this form from an abstract base class, which I will
call BaseForm:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Windows.Forms;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; TestForm
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8&lt;/span&gt;&amp;nbsp;{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;9&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;BaseForm&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;Form&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;10&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;11&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; SomeCommonMethod()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;12&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;13&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;14&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;15&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;16&lt;/span&gt;&amp;nbsp;}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;When I go to edit the UI again, I see this, and it scares
the heck out of me (looks scarier in VS2005)....&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;&lt;/font&gt;&lt;img src="http://www.dotnettechnologies.com/content/binary/ErrorPage1.png" border=0&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
What this is telling you is that it can't render an abstract class BaseForm. So while
you are creating the application, you might&amp;nbsp;remove the abstract&amp;nbsp;identifier
from UI related base classes (with a note that they should be inherited from, not
used, as well as a /TODO marker to make sure you mark it as abstract before deployment). 
&lt;/p&gt;
&lt;p&gt;
Doing this will allow you to inherit from a base class while at the same time edit
the UI.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=11d51691-b09f-4422-aaa5-15a7bf2b628c" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,11d51691-b09f-4422-aaa5-15a7bf2b628c.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Windows</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=a5809af6-e642-4d62-b305-6d99b65685c0</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,a5809af6-e642-4d62-b305-6d99b65685c0.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,a5809af6-e642-4d62-b305-6d99b65685c0.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=a5809af6-e642-4d62-b305-6d99b65685c0</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
You can always grab the ToolTip control out of the toolbox, but I prefer to add a
common function to a base form so I don't have to remember to add this control to
the form. Then, any time I want to add a tooltip, I pass in the control and the text,
and this simple snippet will take care of it for me. I remembered it as I needed to
add some tooltips, which is something the existing application lacks.
</p>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <span style="COLOR: #2b91af">
            <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">        protected</span>
                <span style="COLOR: blue">void</span> SetToolTip(<span style="COLOR: teal">IContainer</span> component, <span style="COLOR: teal">Control</span> ctrl, <span style="COLOR: blue">string</span> tip)
</p>
              <p style="MARGIN: 0px">
        {
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">try</span></p>
              <p style="MARGIN: 0px">
            {
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: teal">ToolTip</span> tooltip
= <span style="COLOR: blue">new</span><span style="COLOR: teal">ToolTip</span>(component);
</p>
              <p style="MARGIN: 0px">
                tooltip.SetToolTip(ctrl,
tip);
</p>
              <p style="MARGIN: 0px">
                tooltip.Active
= <span style="COLOR: blue">true</span>;
</p>
              <p style="MARGIN: 0px">
            }
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">catch</span></p>
              <p style="MARGIN: 0px">
            {
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: green">//Don't
worry</span></p>
              <p style="MARGIN: 0px">
            }
</p>
              <p style="MARGIN: 0px">
        }
</p>
            </div>
            <!--EndFragment-->
          </span>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
Usage: 
</p>
          <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
            <p style="MARGIN: 0px">
              <span style="COLOR: #2b91af">   41</span> SetToolTip(<span style="COLOR: blue">this</span>.components,
lvwCategories, <span style="COLOR: maroon">"Right click for menu options..."</span>);
</p>
          </div>
          <!--EndFragment-->
        </div>
        <!--EndFragment-->
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=a5809af6-e642-4d62-b305-6d99b65685c0" />
      </body>
      <title>Tip of the Day: WinForms and adding tooltips programmatically</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,a5809af6-e642-4d62-b305-6d99b65685c0.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/09/22/TipOfTheDayWinFormsAndAddingTooltipsProgrammatically.aspx</link>
      <pubDate>Tue, 22 Sep 2009 04:38:13 GMT</pubDate>
      <description>&lt;p&gt;
You can always grab the ToolTip control out of the toolbox, but I prefer to add a
common function to a base form so I don't have to remember to add this control to
the form. Then, any time I want to add a tooltip, I pass in the control and the text,
and this simple snippet will take care of it for me. I remembered it as I needed to
add some tooltips, which is something the existing application lacks.
&lt;/p&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: #2b91af"&gt; 
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; SetToolTip(&lt;span style="COLOR: teal"&gt;IContainer&lt;/span&gt; component, &lt;span style="COLOR: teal"&gt;Control&lt;/span&gt; ctrl, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; tip)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: teal"&gt;ToolTip&lt;/span&gt; tooltip
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: teal"&gt;ToolTip&lt;/span&gt;(component);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; tooltip.SetToolTip(ctrl,
tip);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; tooltip.Active
= &lt;span style="COLOR: blue"&gt;true&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: green"&gt;//Don't
worry&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
Usage: 
&lt;/p&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;41&lt;/span&gt;&amp;nbsp;SetToolTip(&lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.components,
lvwCategories, &lt;span style="COLOR: maroon"&gt;"Right click for menu options..."&lt;/span&gt;);
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=a5809af6-e642-4d62-b305-6d99b65685c0" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,a5809af6-e642-4d62-b305-6d99b65685c0.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=0ba9e1fb-994f-4406-beed-b2c12876ad5c</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,0ba9e1fb-994f-4406-beed-b2c12876ad5c.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,0ba9e1fb-994f-4406-beed-b2c12876ad5c.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=0ba9e1fb-994f-4406-beed-b2c12876ad5c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I am getting settled in my new project, and it only took me a week to get rights to
install anything on the laptop! A lot of people would say "Wow, a billable week with
no work!" but personally, the days just drag by. I'd much rather be buried in code.
I did make some good use of the time though, digging into what documentation I could
find and creating a new Functional Specification Document. I did finally get my rights,
so tomorrow will be spent installing things and looking into code again.
</p>
        <p>
I did get some reading done though, and I saw that in VS2010 C# will have optional
and named parameters. I know the VB crowd (of which I come from) will chuckle a little
at that, as that feature has been around forever. Until now, it's required C# developers
to overload functions. Nothing Earth-shattering about this feature, other than as
part of it, C# will support named parameters and default values as well as part of
the implementation (the default values are part of the defiinition of the function).
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=0ba9e1fb-994f-4406-beed-b2c12876ad5c" />
      </body>
      <title>More VS2010 features -- optional parameters in C#</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,0ba9e1fb-994f-4406-beed-b2c12876ad5c.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/09/16/MoreVS2010FeaturesOptionalParametersInC.aspx</link>
      <pubDate>Wed, 16 Sep 2009 04:36:56 GMT</pubDate>
      <description>&lt;p&gt;
I am getting settled in my new project, and it only took me a week to get rights to
install anything on the laptop! A lot of people would say "Wow, a billable week with
no work!" but personally, the days just drag by. I'd much rather be buried in code.
I did make some good use of the time though, digging into what documentation I could
find and creating a new Functional Specification Document. I did finally get my rights,
so tomorrow will be spent installing things and looking into code again.
&lt;/p&gt;
&lt;p&gt;
I did get some reading done though, and I saw that in VS2010 C# will have optional
and named parameters. I know the VB crowd (of which I come from) will chuckle a little
at that, as that feature has been around forever. Until now, it's required C# developers
to overload functions. Nothing Earth-shattering about this feature, other than as
part of it, C# will support named parameters and default values as well as part of
the implementation (the default values are part of the defiinition of the function).
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=0ba9e1fb-994f-4406-beed-b2c12876ad5c" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,0ba9e1fb-994f-4406-beed-b2c12876ad5c.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>General</category>
      <category>VB.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=423c8757-db97-49b5-aa71-e99b424bc5e5</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,423c8757-db97-49b5-aa71-e99b424bc5e5.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,423c8757-db97-49b5-aa71-e99b424bc5e5.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=423c8757-db97-49b5-aa71-e99b424bc5e5</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I posted about <a href="http://www.dotnettechnologies.com/PermaLink,guid,f20dd081-543c-48cb-8e21-cc44f6d2ea5a.aspx" target="_blank">sp_findsp
previously</a> and decided to revisit it. I didn't write it (see previous post
for credit/link) but I did add a bit to it. First, I cleaned it up a bit to make it
easier to read, and second, I made it so that it is a system proc so I could access
it from any db on my server. I may end up doing some cleanup on it's output, but that's
all I had time for for now. So here goes, the new version!
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
            <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">USE</span> master<br />
GO<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PRINT</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Checking
for the existence of this procedure'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IF</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">OBJECT_ID</span>(<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'sp_generate_inserts'</span>,<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'P'</span>)) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOT</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--means,
the procedure already exists</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PRINT</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Procedure
already exists. So, dropping it'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DROP</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PROC</span> sp_findsp<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br />
GO<br /><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PROC</span> sp_findsp
@s <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">varchar</span>(255) 
<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DECLARE</span> @msg <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">varchar</span>(255)
,@ul <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">varchar</span>(255)<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> @s=<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'%'</span> +
@s + <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'%'</span><br />
    <br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'SP
Name'</span>=<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">upper</span>(o.name),
Seq=colid ,<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'SP
Line'</span>=<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">substring</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">text</span>,<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">patindex</span>(@s,<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">text</span>)-5,
30)<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span><span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">syscomments</span> c
, <span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">sysobjects</span> o<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> o.id=c.id<br />
    <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">and</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">patindex</span>(@s,<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">text</span>)
&gt; 0<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ORDER</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BY</span> [name]<br /><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> @msg=<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'*
Stored procedures containing string "'</span> + @s + <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'='</span> + <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">convert</span>(<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">varchar</span>(8),<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">@@rowcount</span>)
+ <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'
*'</span><br /><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> @ul=<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">replicate</span>(<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'*'</span>,<span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">datalength</span>(@msg))<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PRINT</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'
'</span><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PRINT</span> @ul<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PRINT</span> @msg<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PRINT</span> @ul<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br />
GO 
<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Mark
procedure as system object</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">EXEC</span> sys.sp_MS_marksystemobject
sp_findsp<br />
GO<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PRINT</span><span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'Granting
EXECUTE permission on sp_findsp to all users'</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">GRANT</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">EXEC</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ON</span> sp_findsp <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">TO</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><br /><br />
GO<br /><br /><br /></span>
        </p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=423c8757-db97-49b5-aa71-e99b424bc5e5" />
      </body>
      <title>Tip of the Day: sp_findsp revisted</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,423c8757-db97-49b5-aa71-e99b424bc5e5.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/09/01/TipOfTheDaySpfindspRevisted.aspx</link>
      <pubDate>Tue, 01 Sep 2009 04:20:43 GMT</pubDate>
      <description>&lt;p&gt;
I posted about &lt;a href="http://www.dotnettechnologies.com/PermaLink,guid,f20dd081-543c-48cb-8e21-cc44f6d2ea5a.aspx" target=_blank&gt;sp_findsp
previously&lt;/a&gt;&amp;nbsp;and decided to revisit it. I didn't write it (see previous post
for credit/link) but I did add a bit to it. First, I cleaned it up a bit to make it
easier to read, and second, I made it so that it is a system proc so I could access
it from any db on my server. I may end up doing some cleanup on it's output, but that's
all I had time for for now. So here goes, the new version!
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;USE&lt;/span&gt; master&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PRINT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Checking
for the existence of this procedure'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IF&lt;/span&gt; (&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;OBJECT_ID&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'sp_generate_inserts'&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'P'&lt;/span&gt;)) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--means,
the procedure already exists&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PRINT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Procedure
already exists. So, dropping it'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DROP&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PROC&lt;/span&gt; sp_findsp&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PROC&lt;/span&gt; sp_findsp
@s &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;varchar&lt;/span&gt;(255) 
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DECLARE&lt;/span&gt; @msg &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;varchar&lt;/span&gt;(255)
,@ul &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;varchar&lt;/span&gt;(255)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; @s=&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'%'&lt;/span&gt; +
@s + &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'%'&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'SP
Name'&lt;/span&gt;=&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;upper&lt;/span&gt;(o.name),
Seq=colid ,&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'SP
Line'&lt;/span&gt;=&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;substring&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;text&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;patindex&lt;/span&gt;(@s,&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;text&lt;/span&gt;)-5,
30)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;syscomments&lt;/span&gt; c
, &lt;span style="FONT-SIZE: 11px; COLOR: lawngreen; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;sysobjects&lt;/span&gt; o&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; o.id=c.id&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;and&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;patindex&lt;/span&gt;(@s,&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;text&lt;/span&gt;)
&amp;gt; 0&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ORDER&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BY&lt;/span&gt; [name]&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; @msg=&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'*
Stored procedures containing string "'&lt;/span&gt; + @s + &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'='&lt;/span&gt; + &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;convert&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;varchar&lt;/span&gt;(8),&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;@@rowcount&lt;/span&gt;)
+ &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'
*'&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; @ul=&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;replicate&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'*'&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;datalength&lt;/span&gt;(@msg))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PRINT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'
'&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PRINT&lt;/span&gt; @ul&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PRINT&lt;/span&gt; @msg&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PRINT&lt;/span&gt; @ul&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
GO 
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Mark
procedure as system object&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;EXEC&lt;/span&gt; sys.sp_MS_marksystemobject
sp_findsp&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PRINT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'Granting
EXECUTE permission on sp_findsp to all users'&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;GRANT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;EXEC&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ON&lt;/span&gt; sp_findsp &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;TO&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt;
&lt;br&gt;
&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;/span&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=423c8757-db97-49b5-aa71-e99b424bc5e5" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,423c8757-db97-49b5-aa71-e99b424bc5e5.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=f20dd081-543c-48cb-8e21-cc44f6d2ea5a</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,f20dd081-543c-48cb-8e21-cc44f6d2ea5a.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,f20dd081-543c-48cb-8e21-cc44f6d2ea5a.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=f20dd081-543c-48cb-8e21-cc44f6d2ea5a</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
When I go onto a client site, I usually don't have the luxury of designing everything
from scratch. There are times (like on my current engagement) if I were given the
choice, I'd say scrap it, but usually it doesn't happen that way. It is what it is...
been saying that a lot lately!
</p>
        <p>
So one of the tools I find useful is the ability to search for particular field
names in the database. This is very similar to sp_findsp I use, which I have
posted in the past off the net, but I have modified it so it gets registered as a
system procedure.
</p>
        <p>
So here's sp_findfields. It will return a fairly printable representation of the results
of all fields which match the passed in string. It's registered as a system procedure
in this script, so it is accessible to all databases.
</p>
        <p>
Usage: 
</p>
        <p>
          <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">sp_findfields <span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'%Contact%'</span></span>
        </p>
        <p>
This will find all fields with the string 'Item' in it. Note you need to provide
the wildcard characters.
</p>
        <font color="#0000ff" size="2">
          <font color="#0000ff" size="2">
            <p>
              <span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">
                <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">USE</span> master<br />
GO<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IF</span> (<span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span><span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">OBJECT_ID</span>(<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'sp_findfields'</span>,<span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">'P'</span>)) <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">IS</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NOT</span><span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">NULL</span><br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br />
        <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">DROP</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PROCEDURE</span> sp_findfields<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br />
GO<br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">CREATE</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">PROCEDURE</span> sp_findfields 
<br />
(@searchText <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">varchar</span>(50))<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">AS</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BEGIN</span><br />
    <br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">SELECT</span> SchemaName
= <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">LEFT</span>(TABLE_SCHEMA,10),<br />
        TableName = <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">LEFT</span>(TABLE_NAME,
35),<br />
        FieldName = <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">LEFT</span>(COLUMN_NAME,
40),<br />
        DataType = <span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">LEFT</span>(DATA_TYPE,
13),<br />
        DataSize = CHARACTER_MAXIMUM_LENGTH,<br />
        AlloysNulls = IS_NULLABLE<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">FROM</span> INFORMATION_SCHEMA.columns 
<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">WHERE</span> column_name <span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">like</span> @searchText<br />
    <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ORDER</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">BY</span> TableName,
FieldName<br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">END</span><br />
GO<br /><br /><span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">--Mark
procedure as system object</span><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">EXEC</span> sys.sp_MS_marksystemobject
sp_findfields<br />
GO<br /><br /><br /><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">GRANT</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">EXEC</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">ON</span> sp_findfields <span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">TO</span><span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent">public</span><br />
GO</span>
            </p>
          </font>
        </font>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=f20dd081-543c-48cb-8e21-cc44f6d2ea5a" />
      </body>
      <title>Tip of the Day: A system procedure for locating fields in a database</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,f20dd081-543c-48cb-8e21-cc44f6d2ea5a.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/09/01/TipOfTheDayASystemProcedureForLocatingFieldsInADatabase.aspx</link>
      <pubDate>Tue, 01 Sep 2009 04:10:15 GMT</pubDate>
      <description>&lt;p&gt;
When I go onto a client site, I usually don't have the luxury of designing everything
from scratch. There are times (like on my current engagement) if I were given the
choice, I'd say scrap it, but usually it doesn't happen that way. It is what it is...
been saying that a lot lately!
&lt;/p&gt;
&lt;p&gt;
So one of the tools I find useful is the ability to search for particular&amp;nbsp;field
names&amp;nbsp;in the database. This is very similar to sp_findsp I use, which I have
posted in the past off the net, but I have modified it so it gets registered as a
system procedure.
&lt;/p&gt;
&lt;p&gt;
So here's sp_findfields. It will return a fairly printable representation of the results
of all fields which match the passed in string. It's registered as a system procedure
in this script, so it is accessible to all databases.
&lt;/p&gt;
&lt;p&gt;
Usage: 
&lt;/p&gt;
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;sp_findfields &lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'%Contact%'&lt;/span&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p&gt;
This will find all fields with the&amp;nbsp;string 'Item' in it. Note you need to provide
the wildcard characters.
&lt;/p&gt;
&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt; 
&lt;p&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: black; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;USE&lt;/span&gt; master&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IF&lt;/span&gt; (&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;OBJECT_ID&lt;/span&gt;(&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'sp_findfields'&lt;/span&gt;,&lt;span style="FONT-SIZE: 11px; COLOR: red; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;'P'&lt;/span&gt;)) &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;IS&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NOT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;NULL&lt;/span&gt; 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;DROP&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PROCEDURE&lt;/span&gt; sp_findfields&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;CREATE&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;PROCEDURE&lt;/span&gt; sp_findfields 
&lt;br&gt;
(@searchText &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;varchar&lt;/span&gt;(50))&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;AS&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BEGIN&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;SELECT&lt;/span&gt; SchemaName
= &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;LEFT&lt;/span&gt;(TABLE_SCHEMA,10),&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;TableName = &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;LEFT&lt;/span&gt;(TABLE_NAME,
35),&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;FieldName = &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;LEFT&lt;/span&gt;(COLUMN_NAME,
40),&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DataType = &lt;span style="FONT-SIZE: 11px; COLOR: fuchsia; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;LEFT&lt;/span&gt;(DATA_TYPE,
13),&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;DataSize = CHARACTER_MAXIMUM_LENGTH,&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;AlloysNulls = IS_NULLABLE&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;FROM&lt;/span&gt; INFORMATION_SCHEMA.columns 
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;WHERE&lt;/span&gt; column_name &lt;span style="FONT-SIZE: 11px; COLOR: silver; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;like&lt;/span&gt; @searchText&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ORDER&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;BY&lt;/span&gt; TableName,
FieldName&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;END&lt;/span&gt;
&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: teal; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;--Mark
procedure as system object&lt;/span&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;EXEC&lt;/span&gt; sys.sp_MS_marksystemobject
sp_findfields&lt;br&gt;
GO&lt;br&gt;
&lt;br&gt;
&lt;br&gt;
&lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;GRANT&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;EXEC&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;ON&lt;/span&gt; sp_findfields &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;TO&lt;/span&gt; &lt;span style="FONT-SIZE: 11px; COLOR: blue; FONT-FAMILY: Courier New; BACKGROUND-COLOR: transparent"&gt;public&lt;/span&gt;
&lt;br&gt;
GO&lt;/span&gt;
&lt;/p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=f20dd081-543c-48cb-8e21-cc44f6d2ea5a" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,f20dd081-543c-48cb-8e21-cc44f6d2ea5a.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>General</category>
      <category>SQL Tips</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=28e48f37-06e8-4ef1-9abc-b2a44a34dcdf</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,28e48f37-06e8-4ef1-9abc-b2a44a34dcdf.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,28e48f37-06e8-4ef1-9abc-b2a44a34dcdf.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=28e48f37-06e8-4ef1-9abc-b2a44a34dcdf</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Earlier today, I blogged an interview question about reflection. Earlier this year,
as part of the interviewing process I was tasked to write a simple calculator. There
would only be 2 integer inputs with a single operation. For example, if the invoked
the program, and entered in 1 U 2 (U being the operation for addition), the program
would output 3. 
</p>
        <p>
The assignment also mentioned they would want the possibility to expand the operations
later. Instead of just commenting on it, I decided to implement that into the design.
</p>
        <p>
I won't go into retrieving the data from command prompt, but I will provide the project
at the end and you can see how that is accomplished. I made it robust by accounting
for spaces, etc. As a programming concept, you should always program defensively and
assume the work (and you'll be glad with the results).
</p>
        <p>
First, I created a base class each operand would inherit from, so that each works
similarly. The base class <em>OperationBase</em> looks like this:
</p>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">using</span> System.Diagnostics;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">namespace</span> CalcLibrary
</p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    [<span style="COLOR: #2b91af">OperatorIndex</span>(<span style="COLOR: #a31515">""</span>)]
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">OperationBase</span></p>
          <p style="MARGIN: 0px">
    {
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">private</span><span style="COLOR: blue">int</span> value1;
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">private</span><span style="COLOR: blue">int</span> value2;
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> errorInformation
= <span style="COLOR: #2b91af">String</span>.Empty;
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">int</span> Value1
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> value1;
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">set</span> {
value1 = <span style="COLOR: blue">value</span>; }
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">int</span> Value2
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> value2;
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">set</span> {
value2 = <span style="COLOR: blue">value</span>; }
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span> ErrorInformation
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">get</span> { <span style="COLOR: blue">return</span> errorInformation;
}
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">private</span><span style="COLOR: blue">set</span> {
errorInformation = <span style="COLOR: blue">value</span>; }
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: green">//NOTE: We may want
to return a string as the division will round every time, but we will keep this as
an int</span></p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: blue">int</span> Calculate();
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
        <span style="COLOR: blue">protected</span><span style="COLOR: blue">void</span> ErrorHandler(<span style="COLOR: #2b91af">Exception</span> ex)
</p>
          <p style="MARGIN: 0px">
        {
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">try</span></p>
          <p style="MARGIN: 0px">
            {
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: green">//While
in a production app we would want to hide the internals of an error, in this app we
will show them</span></p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">this</span>.ErrorInformation
= <span style="COLOR: #a31515">"An unexpected error occurred ("</span> + <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">StackTrace</span>().GetFrame(2).GetMethod().Name
+ <span style="COLOR: #a31515">")-"</span> + ex.Message;
</p>
          <p style="MARGIN: 0px">
            }
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">catch</span> 
{}
</p>
          <p style="MARGIN: 0px">
        }
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
    }
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">You'll notice this abstract class defines taking two
int inputs (Value1 and Value2), handles the errors, and forces every implementation
to provide a definition of the "Calculate" method. When inheriting from this class, any
operand will be very simple to define -- all it needs to do is determine what to do
for a Calculation, as seen by the addition operand implementation.</font>
          </p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">
            </font> 
</p>
          <font face="Verdana" size="2">
            <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">namespace</span> CalcLibrary
</p>
              <p style="MARGIN: 0px">
{
</p>
              <p style="MARGIN: 0px">
    [<span style="COLOR: #2b91af">OperatorIndex</span>(<span style="COLOR: #a31515">"U"</span>)]
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">AdditionOperand</span> : <span style="COLOR: #2b91af">OperationBase</span></p>
              <p style="MARGIN: 0px">
    {
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">override</span><span style="COLOR: blue">int</span> Calculate()
</p>
              <p style="MARGIN: 0px">
        {
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">return</span><span style="COLOR: blue">this</span>.Value1
+ <span style="COLOR: blue">this</span>.Value2;
</p>
              <p style="MARGIN: 0px">
        }
</p>
              <p style="MARGIN: 0px">
    }
</p>
              <p style="MARGIN: 0px">
}
</p>
            </div>
            <!--EndFragment-->
          </font>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">The next task was to determine which operand to use
given the user's input. We could write an "if" statement or a factory method, but
I wanted to make sure if anyone came in to add a new operand, they would not have
to change any code -- just add a new class, inherit from <em>OperationBase</em> and
implement the Calculate() method. To accomplish this task, I decided to use reflection.
By decorating each Operand class with an attribute, I could designate how it reacts
to the inputs. </font>
          </p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">
            </font> 
</p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">First, I needed to define my attribute:</font>
          </p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">
            </font> 
</p>
          <font face="Verdana" size="2">
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
              <span style="COLOR: blue">using</span> System;
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
 
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
              <span style="COLOR: blue">namespace</span> CalcLibrary
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
{
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
    [System.<span style="COLOR: #2b91af">AttributeUsage</span>(System.<span style="COLOR: #2b91af">AttributeTargets</span>.Class)]
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">OperatorIndex</span> :
System.<span style="COLOR: #2b91af">Attribute</span></p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
    {
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">string</span> OperatorId
= <span style="COLOR: #2b91af">String</span>.Empty;
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
        <span style="COLOR: blue">public</span> OperatorIndex(<span style="COLOR: blue">string</span> operatorId)
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
        {
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
            OperatorId = operatorId;
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
        }
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
    }
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
}
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
 
</p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
              <font face="Verdana" size="2">Next, I need to decorate my operands with the appropriate
attribute. Again, I will use the AdditionOperand, which is indicated by the "U" notation.
When I define my class, I decorate it with the attribute letter I want to use to define
that function.</font>
            </p>
            <p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New">
              <font size="2">
              </font>
              <font color="#2b91af" size="2">
                <font color="#2b91af" size="2"> 
</font>
              </font>
            </p>
          </font>
          <font face="Verdana" size="2">
            <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
    [<span style="COLOR: #2b91af">OperatorIndex</span>(<span style="COLOR: #a31515">"U"</span>)]
</p>
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">public</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">AdditionOperand</span> : <span style="COLOR: #2b91af">OperationBase</span></p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                </span> 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                  <font face="Verdana" color="#000000" size="2">Now that
I have defined my operations, I need to use them. I created a publically exposed static
class called <em>CalcEngine</em> which loads all the operations, validates the inputs,
and processes the calculations. I created this as a class library so it could be used
with a console application (as it is being called from in the supplied example), a
web application, etc.</font>
                </span>
              </p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                  <font face="Verdana" color="#000000" size="2">
                  </font>
                </span> 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                  <font face="Verdana" color="#000000" size="2">In the
constructor, I call a method <em>LoadOperators()</em> which uses LINQ to Reflection
to quickly retrieve all classes of type <em>OperatorBase</em> and have the <em>OperatorIndex</em> defined.
I load the resules into a dictionary object so I can quickly retrieve them for my
calculations. Below is how I load the operators using LINQ to Reflection.</font>
                </span>
              </p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                  <font face="Verdana" color="#000000" size="2">
                  </font>
                </span> 
</p>
              <span style="COLOR: #2b91af">
                <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
                  <p style="MARGIN: 0px">
                    <span style="COLOR: blue">private</span>
                    <span style="COLOR: blue">static</span>
                    <span style="COLOR: blue">void</span> LoadOperators()
</p>
                  <p style="MARGIN: 0px">
        {
</p>
                  <p style="MARGIN: 0px">
            <span style="COLOR: green">//Using
LINQ to Reflection, load all classes from the assembly that inherit from our base
Operator type, </span></p>
                  <p style="MARGIN: 0px">
            <span style="COLOR: green">//and
have the attribute set into a dictionary, so we can quickly reference the operator
we want</span></p>
                  <p style="MARGIN: 0px">
            operations =
</p>
                  <p style="MARGIN: 0px">
                (<span style="COLOR: blue">from</span> a <span style="COLOR: blue">in</span><span style="COLOR: #2b91af">AppDomain</span>.CurrentDomain.GetAssemblies()
</p>
                  <p style="MARGIN: 0px">
                <span style="COLOR: blue">from</span> t <span style="COLOR: blue">in</span> a.GetTypes()
</p>
                  <p style="MARGIN: 0px">
                <span style="COLOR: blue">where</span><span style="COLOR: #2b91af">Attribute</span>.IsDefined(t,<span style="COLOR: blue">typeof</span>(<span style="COLOR: #2b91af">OperatorIndex</span>))
</p>
                  <p style="MARGIN: 0px">
                <span style="COLOR: blue">where</span> t.BaseType
== <span style="COLOR: blue">typeof</span>(<span style="COLOR: #2b91af">OperationBase</span>)
</p>
                  <p style="MARGIN: 0px">
                <span style="COLOR: blue">let</span> attribute
= <span style="COLOR: #2b91af">Attribute</span>.GetCustomAttribute(t,<span style="COLOR: blue">typeof</span>(<span style="COLOR: #2b91af">OperatorIndex</span>)) <span style="COLOR: blue">as</span><span style="COLOR: #2b91af">OperatorIndex</span></p>
                  <p style="MARGIN: 0px">
                <span style="COLOR: blue">where</span> attribute.OperatorId
!= <span style="COLOR: #a31515">""</span></p>
                  <p style="MARGIN: 0px">
                <span style="COLOR: blue">select</span></p>
                  <p style="MARGIN: 0px">
                    <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">OperatorDetails</span></p>
                  <p style="MARGIN: 0px">
                   
{
</p>
                  <p style="MARGIN: 0px">
                   
    AssemName = a.GetName().Name,
</p>
                  <p style="MARGIN: 0px">
                   
    ClassName = t.FullName,
</p>
                  <p style="MARGIN: 0px">
                   
    OperatorId = attribute.OperatorId
</p>
                  <p style="MARGIN: 0px">
                   
}).ToDictionary(p =&gt; p.OperatorId,p =&gt; p);
</p>
                  <p style="MARGIN: 0px">
 
</p>
                  <p style="MARGIN: 0px">
        }
</p>
                </div>
                <!--EndFragment-->
              </span>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                  <font face="Verdana" color="#000000" size="2">The main <em>Calculate </em>method
validates the input, retrieves the right operand key from the dictionary, late binds
to the proper <em>OperatorBase</em> class and invokes the <em>Calculate() </em>method,
as seen below.</font>
                </span>
              </p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">
                  <font face="Verdana" color="#000000" size="2">
                  </font>
                </span> 
</p>
              <span style="COLOR: #2b91af">
                <font face="Verdana" color="#000000" size="2">
                  <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
                    <p style="MARGIN: 0px">
                <span style="COLOR: green">//locate
the correct operator from our dictionary</span></p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">OperatorDetails</span> operatorInfo
= operations[mathOperator];
</p>
                    <p style="MARGIN: 0px">
 
</p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: green">//dynamically
load the operator class. I chose to do it using reflection so that we wouldn't need
a</span></p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: green">//factory,
which would need to be changed every time a new operator was added.</span></p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: green">//ENHANCEMENT:
you could actually detect other assemblies and load them as well</span></p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">Type</span> calcClass
= <span style="COLOR: #2b91af">Type</span>.GetType(operatorInfo.ClassName);
</p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">OperationBase</span> calculator
= (<span style="COLOR: #2b91af">OperationBase</span>) <span style="COLOR: #2b91af">Activator</span>.CreateInstance(calcClass);
</p>
                    <p style="MARGIN: 0px">
                calculator.Value1
= value1;
</p>
                    <p style="MARGIN: 0px">
                calculator.Value2
= value2;
</p>
                    <p style="MARGIN: 0px">
                <span style="COLOR: blue">int</span> calculatedResult
= calculator.Calculate();
</p>
                  </div>
                  <!--EndFragment-->
                </font>
              </span>
            </div>
          </font>
        </div>
        <font face="Verdana" size="2">
          <font face="Verdana" size="2">
          </font>
        </font>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <font face="Verdana" size="2">
            <font face="Verdana" size="2">
            </font>
          </font> 
</div>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <font face="Verdana" size="2">
            <font face="Verdana" size="2">Using
a console application, it looks like this:</font>
          </font>
        </div>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <font face="Verdana" size="2">
            <font face="Verdana" size="2">
            </font>
          </font> 
</div>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <font face="Verdana" size="2">
            <font face="Verdana" size="2">
              <!--EndFragment-->
            </font>
            <!--EndFragment-->
          </font>
        </div>
        <p>
          <img src="http://www.dotnettechnologies.com/content/binary/calc_example.png" border="0" />
        </p>
        <p>
Here's the sample code to look at and play with.. Enjoy!
</p>
        <p>
 
</p>
        <a href="http://www.dotnettechnologies.com/content/binary/SampleProj.zip">SampleProj.zip
(89.4 KB)</a>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=28e48f37-06e8-4ef1-9abc-b2a44a34dcdf" />
      </body>
      <title>How I have used reflection</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,28e48f37-06e8-4ef1-9abc-b2a44a34dcdf.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/25/HowIHaveUsedReflection.aspx</link>
      <pubDate>Tue, 25 Aug 2009 05:12:16 GMT</pubDate>
      <description>&lt;p&gt;
Earlier today, I blogged an interview question about reflection. Earlier this year,
as part of the interviewing process I was tasked to write a simple calculator. There
would only be 2 integer inputs with a single operation. For example, if the invoked
the program, and entered in 1 U 2 (U being the operation for addition), the program
would output 3. 
&lt;/p&gt;
&lt;p&gt;
The assignment also mentioned they would want the possibility to expand the operations
later. Instead of just commenting on it, I decided to implement that into the design.
&lt;/p&gt;
&lt;p&gt;
I won't go into retrieving the data from command prompt, but I will provide the project
at the end and you can see how that is accomplished. I made it robust by accounting
for spaces, etc. As a programming concept, you should always program defensively and
assume the work (and you'll be glad with the results).
&lt;/p&gt;
&lt;p&gt;
First, I created a base class each operand would inherit from, so that each works
similarly. The base class &lt;em&gt;OperationBase&lt;/em&gt; looks like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Diagnostics;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; CalcLibrary
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;""&lt;/span&gt;)]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;OperationBase&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; value1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; value2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; errorInformation
= &lt;span style="COLOR: #2b91af"&gt;String&lt;/span&gt;.Empty;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Value1
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; value1;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
value1 = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Value2
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; value2;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
value2 = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; ErrorInformation
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;get&lt;/span&gt; { &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; errorInformation;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;set&lt;/span&gt; {
errorInformation = &lt;span style="COLOR: blue"&gt;value&lt;/span&gt;; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//NOTE: We may want
to return a string as the division will round every time, but we will keep this as
an int&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Calculate();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;protected&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; ErrorHandler(&lt;span style="COLOR: #2b91af"&gt;Exception&lt;/span&gt; ex)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: green"&gt;//While
in a production app we would want to hide the internals of an error, in this app we
will show them&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.ErrorInformation
= &lt;span style="COLOR: #a31515"&gt;"An unexpected error occurred ("&lt;/span&gt; + &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;StackTrace&lt;/span&gt;().GetFrame(2).GetMethod().Name
+ &lt;span style="COLOR: #a31515"&gt;")-"&lt;/span&gt; + ex.Message;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt;&amp;nbsp;
{}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;You'll notice this abstract class defines taking two int
inputs (Value1 and Value2), handles the errors, and forces every implementation to
provide a definition of the "Calculate" method. When inheriting from this class,&amp;nbsp;any
operand will be very simple to define -- all it needs to do is determine what to do
for a Calculation, as seen by the addition operand implementation.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;font face=Verdana size=2&gt; 
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; CalcLibrary
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"U"&lt;/span&gt;)]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;AdditionOperand&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;OperationBase&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; Calculate()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.Value1
+ &lt;span style="COLOR: blue"&gt;this&lt;/span&gt;.Value2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/font&gt; 
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;The next task was to determine which operand to use given
the user's input. We could write an "if" statement or a factory method, but I wanted
to make sure if anyone came in to add a new operand, they would not have to change
any code -- just add a new class, inherit from &lt;em&gt;OperationBase&lt;/em&gt; and implement
the Calculate() method.&amp;nbsp;To accomplish this task, I decided to use reflection.
By decorating each Operand class with an attribute, I could designate how it reacts
to the inputs. &lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;First, I needed to define my attribute:&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;font face=Verdana size=2&gt; 
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; CalcLibrary
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
{
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [System.&lt;span style="COLOR: #2b91af"&gt;AttributeUsage&lt;/span&gt;(System.&lt;span style="COLOR: #2b91af"&gt;AttributeTargets&lt;/span&gt;.Class)]
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt; :
System.&lt;span style="COLOR: #2b91af"&gt;Attribute&lt;/span&gt;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; OperatorId
= &lt;span style="COLOR: #2b91af"&gt;String&lt;/span&gt;.Empty;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; OperatorIndex(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; operatorId)
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; OperatorId = operatorId;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
}
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;font face=Verdana size=2&gt;Next, I need to decorate my operands with the appropriate
attribute. Again, I will use the AdditionOperand, which is indicated by the "U" notation.
When I define my class, I decorate it with the attribute letter I want to use to define
that function.&lt;/font&gt;
&lt;/p&gt;
&lt;p style="FONT-SIZE: 8pt; BACKGROUND: white; MARGIN: 0px; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;font size=2&gt;&lt;/font&gt;&lt;font color=#2b91af size=2&gt;&lt;font color=#2b91af size=2&gt;&amp;nbsp;
&lt;/p&gt;
&lt;/font&gt;&gt;&lt;font face=Verdana size=2&gt; 
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; [&lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt;(&lt;span style="COLOR: #a31515"&gt;"U"&lt;/span&gt;)]
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;AdditionOperand&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;OperationBase&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt;Now that I have
defined my operations, I need to use them. I created a publically exposed static class
called &lt;em&gt;CalcEngine&lt;/em&gt; which loads all the operations, validates the inputs, and
processes the calculations. I created this as a class library so it could be used
with a console application (as it is being called from in the supplied example), a
web application, etc.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt;In the constructor,
I call a method &lt;em&gt;LoadOperators()&lt;/em&gt; which uses LINQ to Reflection to quickly
retrieve all classes of type &lt;em&gt;OperatorBase&lt;/em&gt; and have the &lt;em&gt;OperatorIndex&lt;/em&gt; defined.
I load the resules into a dictionary object so I can quickly retrieve them for my
calculations. Below is how I load the operators using LINQ to Reflection.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span style="COLOR: #2b91af"&gt; 
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;void&lt;/span&gt; LoadOperators()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//Using
LINQ to Reflection, load all classes from the assembly that inherit from our base
Operator type, &lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//and
have the attribute set into a dictionary, so we can quickly reference the operator
we want&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; operations =
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; (&lt;span style="COLOR: blue"&gt;from&lt;/span&gt; a &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;AppDomain&lt;/span&gt;.CurrentDomain.GetAssemblies()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;from&lt;/span&gt; t &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; a.GetTypes()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;where&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Attribute&lt;/span&gt;.IsDefined(t,&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt;))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;where&lt;/span&gt; t.BaseType
== &lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;OperationBase&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;let&lt;/span&gt; attribute
= &lt;span style="COLOR: #2b91af"&gt;Attribute&lt;/span&gt;.GetCustomAttribute(t,&lt;span style="COLOR: blue"&gt;typeof&lt;/span&gt;(&lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt;)) &lt;span style="COLOR: blue"&gt;as&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;OperatorIndex&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;where&lt;/span&gt; attribute.OperatorId
!= &lt;span style="COLOR: #a31515"&gt;""&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;select&lt;/span&gt; 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;OperatorDetails&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; AssemName = a.GetName().Name,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; ClassName = t.FullName,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; OperatorId = attribute.OperatorId
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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;
}).ToDictionary(p =&amp;gt; p.OperatorId,p =&amp;gt; p);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt;The main &lt;em&gt;Calculate &lt;/em&gt;method
validates the input, retrieves the right operand key from the dictionary, late binds
to the proper &lt;em&gt;OperatorBase&lt;/em&gt; class and invokes the &lt;em&gt;Calculate() &lt;/em&gt;method,
as seen below.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span style="COLOR: #2b91af"&gt;&lt;font face=Verdana color=#000000 size=2&gt; 
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: green"&gt;//locate
the correct operator from our dictionary&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: #2b91af"&gt;OperatorDetails&lt;/span&gt; operatorInfo
= operations[mathOperator];
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: green"&gt;//dynamically
load the operator class. I chose to do it using reflection so that we wouldn't need
a&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: green"&gt;//factory,
which would need to be changed every time a new operator was added.&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: green"&gt;//ENHANCEMENT:
you could actually detect other assemblies and load them as well&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: #2b91af"&gt;Type&lt;/span&gt; calcClass
= &lt;span style="COLOR: #2b91af"&gt;Type&lt;/span&gt;.GetType(operatorInfo.ClassName);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: #2b91af"&gt;OperationBase&lt;/span&gt; calculator
= (&lt;span style="COLOR: #2b91af"&gt;OperationBase&lt;/span&gt;) &lt;span style="COLOR: #2b91af"&gt;Activator&lt;/span&gt;.CreateInstance(calcClass);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; calculator.Value1
= value1;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; calculator.Value2
= value2;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; calculatedResult
= calculator.Calculate();
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/font&gt;
&lt;/font&gt;&gt;&gt;
&lt;/div&gt;
&lt;font face=Verdana size=2&gt;&lt;font face=Verdana size=2&gt;&lt;/font&gt;&lt;/font&gt;&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;font face=Verdana size=2&gt;&lt;font face=Verdana size=2&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;
&lt;/div&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;font face=Verdana size=2&gt;&lt;font face=Verdana size=2&gt;Using
a console application, it looks like this:&lt;/font&gt;&lt;/font&gt;
&lt;/div&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;font face=Verdana size=2&gt;&lt;font face=Verdana size=2&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;
&lt;/div&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;font face=Verdana size=2&gt;&lt;font face=Verdana size=2&gt;
&lt;!--EndFragment--&gt;&lt;/font&gt;
&lt;!--EndFragment--&gt;&lt;/font&gt;
&lt;/div&gt;
&lt;p&gt;
&lt;img src="http://www.dotnettechnologies.com/content/binary/calc_example.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
Here's the sample code to look at and play with.. Enjoy!
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;a href="http://www.dotnettechnologies.com/content/binary/SampleProj.zip"&gt;SampleProj.zip
(89.4 KB)&lt;/a&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=28e48f37-06e8-4ef1-9abc-b2a44a34dcdf" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,28e48f37-06e8-4ef1-9abc-b2a44a34dcdf.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=4a377aac-37cf-4611-9579-20cec1061335</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,4a377aac-37cf-4611-9579-20cec1061335.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,4a377aac-37cf-4611-9579-20cec1061335.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=4a377aac-37cf-4611-9579-20cec1061335</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today has been an insanely busy day, but I have so much I want to blog about, and
this one won't wait. A few days ago, as I was using some code I found on the net,
I <a href="http://www.dotnettechnologies.com/PermaLink,guid,5428d2b4-f00b-47fc-91a9-6825caa723b6.aspx" target="_blank">commented
here</a> about the over-use of the <em>var</em> keyword.
</p>
        <p>
Seems I am not the only one who has an opinion on the matter. I subscribe to the CodeProject
newsletter, and each issue features a survey. This week, the survey relates to the
opinion of the <em>var</em> type in C#. You can see the <a href="http://www.codeproject.com/script/Surveys/Results.aspx?srvid=950" target="_blank">survey
results here</a>. Make sure you click through to the "optional text answers" for some
funny comments (and a few relevant ones as well).
</p>
        <p>
The interesting thing to note from the survey is that the answers tend to skew towards
the "never use that scenario" range. The two areas where it is most prevalent is with
LINQ, and with anonymous types, which makes total sense. 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=4a377aac-37cf-4611-9579-20cec1061335" />
      </body>
      <title>Topical: The use of the var keyword revisited</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,4a377aac-37cf-4611-9579-20cec1061335.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/25/TopicalTheUseOfTheVarKeywordRevisited.aspx</link>
      <pubDate>Tue, 25 Aug 2009 04:28:04 GMT</pubDate>
      <description>&lt;p&gt;
Today has been an insanely busy day, but I have so much I want to blog about, and
this one won't wait. A few days ago, as I was using some code I found on the net,
I &lt;a href="http://www.dotnettechnologies.com/PermaLink,guid,5428d2b4-f00b-47fc-91a9-6825caa723b6.aspx" target=_blank&gt;commented
here&lt;/a&gt; about the over-use of the &lt;em&gt;var&lt;/em&gt; keyword.
&lt;/p&gt;
&lt;p&gt;
Seems I am not the only one who has an opinion on the matter. I subscribe to the CodeProject
newsletter, and each issue features a survey. This week, the survey relates to the
opinion of the &lt;em&gt;var&lt;/em&gt; type in C#. You can see the &lt;a href="http://www.codeproject.com/script/Surveys/Results.aspx?srvid=950" target=_blank&gt;survey
results here&lt;/a&gt;. Make sure you click through to the "optional text answers" for some
funny comments (and a few relevant ones as well).
&lt;/p&gt;
&lt;p&gt;
The interesting thing to note from the survey is that the answers tend to skew towards
the "never use that scenario" range. The two areas where it is most prevalent is with
LINQ, and with anonymous types, which makes total sense. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=4a377aac-37cf-4611-9579-20cec1061335" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,4a377aac-37cf-4611-9579-20cec1061335.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=b94da6c0-6f70-4eee-841d-2d4236253c92</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,b94da6c0-6f70-4eee-841d-2d4236253c92.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,b94da6c0-6f70-4eee-841d-2d4236253c92.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=b94da6c0-6f70-4eee-841d-2d4236253c92</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <strong>Question: </strong>What's reflection, and how have you used it to solve a
problem?
</p>
        <p>
          <strong>Answer: </strong>Reflection is a way to look at assembly metadata and look
in and see what is contained. It also allows you to use late binding and call methods
within those assembles.
</p>
        <p>
For the second part, a simple explanation is all you need to show that you understand
how it is used.
</p>
        <p>
So what if you've enver used reflection? First, shame on you (kidding!). It DOES serve
a very important purpose and allows for some great solutions, especially at an architectural
level. If you've never used it, I recommend immediately trying it out, and you'll
find many, many uses. Here's a <a href="http://www.codeguru.com/csharp/csharp/cs_misc/reflection/article.php/c4257" target="_blank">tutorial</a> I
found that looks decent. That way, when asked this question (and I get this one a
lot) you can answer how you *might* really use it. Honestly, you've probably used
it and didn't realize it if you've added certain attributes to your code.
</p>
        <p>
I have used reflection for everything from identifying certain classes and functions.
For example, for a coding sample, I used LINQ for Reflection and attributes to identify
classes which supported certain calculations. By doing this, I could add more
functions dynamically and the UI would pick it without changing code. Since LINQ for
Reflection is not discussed much, I'll post some about that later.
</p>
        <p>
There are some costs associated with Reflection though. Speed! Late Binding is slower
by it's nature, as well as all the processing looking for methods, so plan and use
wisely!
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=b94da6c0-6f70-4eee-841d-2d4236253c92" />
      </body>
      <title>Tip of the Day: Technical Interview question: What's Reflection?</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,b94da6c0-6f70-4eee-841d-2d4236253c92.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/24/TipOfTheDayTechnicalInterviewQuestionWhatsReflection.aspx</link>
      <pubDate>Mon, 24 Aug 2009 14:27:02 GMT</pubDate>
      <description>&lt;p&gt;
&lt;strong&gt;Question: &lt;/strong&gt;What's reflection, and how have you used it to solve a
problem?
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Answer: &lt;/strong&gt;Reflection is a way to look at assembly metadata and look
in and see what is contained. It also allows you to use late binding and call methods
within those assembles.
&lt;/p&gt;
&lt;p&gt;
For the second part, a simple explanation is all you need to show that you understand
how it is used.
&lt;/p&gt;
&lt;p&gt;
So what if you've enver used reflection? First, shame on you (kidding!). It DOES serve
a very important purpose and allows for some great solutions, especially at an architectural
level. If you've never used it, I recommend immediately trying it out, and you'll
find many, many uses. Here's a &lt;a href="http://www.codeguru.com/csharp/csharp/cs_misc/reflection/article.php/c4257" target=_blank&gt;tutorial&lt;/a&gt; I
found that looks decent. That way, when asked this question (and I get this one a
lot) you can answer how you *might* really use it. Honestly, you've probably used
it and didn't realize it if you've added certain attributes to your code.
&lt;/p&gt;
&lt;p&gt;
I have used reflection for everything from identifying certain classes and functions.
For example, for a coding sample, I used LINQ for Reflection and attributes to identify
classes which supported certain calculations. By doing this,&amp;nbsp;I could add more
functions dynamically and the UI would pick it without changing code. Since LINQ for
Reflection is not discussed much, I'll post some about that later.
&lt;/p&gt;
&lt;p&gt;
There are some costs associated with Reflection though. Speed! Late Binding is slower
by it's nature, as well as all the processing looking for methods, so plan and use
wisely!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=b94da6c0-6f70-4eee-841d-2d4236253c92" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,b94da6c0-6f70-4eee-841d-2d4236253c92.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=1249a156-8ee0-439c-8a62-e368cd50e004</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,1249a156-8ee0-439c-8a62-e368cd50e004.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,1249a156-8ee0-439c-8a62-e368cd50e004.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=1249a156-8ee0-439c-8a62-e368cd50e004</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As a full time developer, I search the web... a lot. If you are writing a lot of new
code without at least searching to see what exists, you're either getting paid by
the hour (or line of code), stubborn or a glutton for punishment. Even if I don't
use it, I can get some guidance on what someone else tried, and how it worked out
before I start coding. Granted, it usually requires a lot of refactoring the code
to my standards or needs, but it's a great start.
</p>
        <p>
As I was thinking of things I wanted to put on my site, I realized it would be nice
to share my "favorites"...sort of. If I found something useful, I wanted to be able
to show what it was, how I found it useful and where someone else can find it. In
a way, I am also helping to promote someone else's hard work and improving their search
engine visibility to return the favor of their sharing their work.
</p>
        <p>
Out of this, I came up with an idea for a "Useful Links" section. I wanted to be able
to add links and commentary, and also add it to my <a href="http://www.dotnettechnologies.com/PermaLink,guid,308bd3f2-4d3c-48b6-84f2-1dbe04982eed.aspx" target="_blank">Activity
Aggregator</a> to show help show the content of the site has changed. Later, as I
was using Bing, I got the idea to add some webthumbs to enhance the page graphically,
so the reader would know what the site looked like before going there. I also needed
to add an admin page for creating the useful links (and ultimately maintaining them
-- which is on my TODO list). I'll also leave out the icon creation part, although
I really need to farm out for a new cool looking icon, which is also on my list of
things to do.
</p>
        <p>
I'll skip the admin section, as it's just data entry fields. The process for creating
the entries does change a bit, as I needed to do a few extra steps.
</p>
        <ol>
          <li>
Save the UsefulLink class 
</li>
          <li>
Default the webthumb image to a default "safety" image in case we can't get a webthumb 
</li>
          <li>
Make a request to get a webthumb image of the target site 
</li>
          <li>
Once the image is retrieved, update the UsefulLink record to point to the new webthumb 
</li>
          <li>
Update the Activity Aggregator to show we have a new useful link.</li>
        </ol>
        <p>
Step 3 is where things get tricky. How in all getout do we get webthumb images? There
are <a href="http://www.acasystems.com/en/web-thumb-activex/faq-generate-image-from-html-in-c-sharp.htm" target="_blank">controls </a>out
there you can get, and they are reasonably priced as well. But I decided to keep searching
so I could write this one on my own, as it seems like an interesting challenge.
</p>
        <p>
My next thought was to create my own service to do this. There's plenty of code
out there, but the easiest way to do this would require some WinForms programming.
Don't get me wrong, I LOVE programming WinForms. The problem is I don't want to have
to install it everywhere I am at, as I need a service. I could possibly create a Web
and Windows service to do this as well, but that seemed overly complex. So I did a
search, and I found <a href="http://webthumb.bluga.net/home" target="_blank">this</a>,
which is a service which does it for you. What's even nicer is that they expose a
nice API to use. As of now, the first 100 images a month are free, and after that,
the fees are very reasonable. Even though I doubt I will go over 100 images per month,
I am so impressed I may pay just to keep the service going.
</p>
        <p>
I was also able to find some c# code to make learning the API fast. I did end up changing
it some, but in general it worked very well. You can find it <a href="http://stackoverflow.com/questions/701680/how-do-i-save-a-web-page-to-image-using-c" target="_blank">here</a>.
</p>
        <p>
So when the service returns with my image (I used the medium size), I save it to a
thumbs directory (had to add write permissions to the directory, or I got an obscure GDI+
error), and call a method on my UsefulLink class to update the record with the thumbnail
image. I name the image with the current date and time so that the names will be unique
as well.
</p>
        <p>
Finally, once I have downloaded the image and updated the UsefulLink record, I add
a call to my Activity class which creates an entry for the Activity Aggregator.
As I add more items to throw into the Activity Aggregator, I am considering refactoring
things to do some delegate multicasting for all the updates, or perhaps creating a
factory where you provide class (should be easy since my business objects
share the same base class) or interface, and it knows how to create the activity
record instead of making individual calls. That's on my list down the road. :)
</p>
        <p>
Here's what the Activity Aggrgator looks like, with a special Useful Link icon(<img src="http://www.dotnettechnologies.com/content/binary/useful_link.png" border="0" />):
</p>
        <p>
 
</p>
        <p>
          <img src="http://www.dotnettechnologies.com/content/binary/DevArea_new.png" border="0" />
        </p>
        <p>
And here's what the Useful Link section (which has the webthumbs) looks like. I will
only be showing 10 at a time to save web page real estate. But I also don't want to
lose older links off the page. I am debating now whether to use paging, or just have a
smaller hyperlink-only section below the most recent links. I am leaning towards paging,
as I have a very neat service I want to implement which makes paging and sorting incredibly
fast and easy (more on that someday.. I need to upgrade it to user .Net 3.5 functionality
before I post it).
</p>
        <p>
 
</p>
        <img src="http://www.dotnettechnologies.com/content/binary/UsefulLinks.png" border="0" />
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=1249a156-8ee0-439c-8a62-e368cd50e004" />
      </body>
      <title>Useful Links -- An overview</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,1249a156-8ee0-439c-8a62-e368cd50e004.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/23/UsefulLinksAnOverview.aspx</link>
      <pubDate>Sun, 23 Aug 2009 16:28:00 GMT</pubDate>
      <description>&lt;p&gt;
As a full time developer, I search the web... a lot. If you are writing a lot of new
code without at least searching to see what exists, you're either getting paid by
the hour (or line of code), stubborn or a glutton for punishment. Even if I don't
use it, I can get some guidance on what someone else tried, and how it worked out
before I start coding. Granted, it usually requires a lot of refactoring the code
to my standards or needs, but it's a great start.
&lt;/p&gt;
&lt;p&gt;
As I was thinking of things I wanted to put on my site, I realized it would be nice
to share my "favorites"...sort of. If I found something useful, I wanted to be able
to show what it was, how I found it useful and where someone else can find it. In
a way, I am also helping to promote someone else's hard work and improving their search
engine visibility to return the favor of their sharing their work.
&lt;/p&gt;
&lt;p&gt;
Out of this, I came up with an idea for a "Useful Links" section. I wanted to be able
to add links and commentary, and also add it to my &lt;a href="http://www.dotnettechnologies.com/PermaLink,guid,308bd3f2-4d3c-48b6-84f2-1dbe04982eed.aspx" target=_blank&gt;Activity
Aggregator&lt;/a&gt; to show help show the content of the site has changed. Later, as I
was using Bing, I got the idea to add some webthumbs to enhance the page graphically,
so the reader would know what the site looked like before going there. I also needed
to add an admin page for creating the useful links (and ultimately maintaining them
-- which is on my TODO list). I'll also leave out the icon creation part, although
I really need to farm out for a new cool looking icon, which is also on my list of
things to do.
&lt;/p&gt;
&lt;p&gt;
I'll skip the admin section, as it's just data entry fields. The process for creating
the entries does change a bit, as I needed to do a few extra steps.
&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;
Save the UsefulLink class 
&lt;li&gt;
Default the webthumb image to a default "safety" image in case we can't get a webthumb 
&lt;li&gt;
Make a request to get a webthumb image of the target site 
&lt;li&gt;
Once the image is retrieved, update the UsefulLink record to point to the new webthumb 
&lt;li&gt;
Update the Activity Aggregator to show we have a new useful link.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;
Step 3 is where things get tricky. How in all getout do we get webthumb images? There
are &lt;a href="http://www.acasystems.com/en/web-thumb-activex/faq-generate-image-from-html-in-c-sharp.htm" target=_blank&gt;controls &lt;/a&gt;out
there you can get, and they are reasonably priced as well. But I decided to keep searching
so I could write this one on my own, as it seems like an interesting challenge.
&lt;/p&gt;
&lt;p&gt;
My&amp;nbsp;next thought was to create my own service to do this. There's plenty of code
out there, but the easiest way to do this would require some WinForms programming.
Don't get me wrong, I LOVE programming WinForms. The problem is I don't want to have
to install it everywhere I am at, as I need a service. I could possibly create a Web
and Windows service to do this as well, but that seemed overly complex. So I did a
search, and I found &lt;a href="http://webthumb.bluga.net/home" target=_blank&gt;this&lt;/a&gt;,
which is a service which does it for you. What's even nicer is that they expose a
nice API to use. As of now, the first 100 images a month are free, and after that,
the fees are very reasonable. Even though I doubt I will go over 100 images per month,
I am so impressed I may pay just to keep the service going.
&lt;/p&gt;
&lt;p&gt;
I was also able to find some c# code to make learning the API fast. I did end up changing
it some, but in general it worked very well. You can find it &lt;a href="http://stackoverflow.com/questions/701680/how-do-i-save-a-web-page-to-image-using-c" target=_blank&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
So when the service returns with my image (I used the medium size), I save it to a
thumbs directory (had to add write permissions to the directory, or I got an obscure&amp;nbsp;GDI+
error), and call a method on my UsefulLink class to update the record with the thumbnail
image. I name the image with the current date and time so that the names will be unique
as well.
&lt;/p&gt;
&lt;p&gt;
Finally, once I have downloaded the image and updated the UsefulLink record, I add
a call to my Activity class which creates an entry&amp;nbsp;for the Activity Aggregator.
As I add more items to throw into the Activity Aggregator, I am considering refactoring
things to do some delegate multicasting for all the updates, or perhaps creating a
factory where you provide&amp;nbsp;class (should be&amp;nbsp;easy since my business objects
share the same base class)&amp;nbsp;or interface, and it knows how to create the activity
record instead of making individual calls. That's on my list down the road. :)
&lt;/p&gt;
&lt;p&gt;
Here's what the Activity Aggrgator looks like, with a special Useful Link icon(&lt;img src="http://www.dotnettechnologies.com/content/binary/useful_link.png" border=0&gt;):
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.dotnettechnologies.com/content/binary/DevArea_new.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
And here's what the Useful Link section (which has the webthumbs) looks like. I will
only be showing 10 at a time to save web page real estate. But I also don't want to
lose older links off the page. I am debating now whether to use paging, or just have&amp;nbsp;a
smaller hyperlink-only section below the most recent links. I am leaning towards paging,
as I have a very neat service I want to implement which makes paging and sorting incredibly
fast and easy (more on that someday.. I need to upgrade it to user .Net 3.5 functionality
before I post it).
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img src="http://www.dotnettechnologies.com/content/binary/UsefulLinks.png" border=0&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=1249a156-8ee0-439c-8a62-e368cd50e004" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,1249a156-8ee0-439c-8a62-e368cd50e004.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=5428d2b4-f00b-47fc-91a9-6825caa723b6</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,5428d2b4-f00b-47fc-91a9-6825caa723b6.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,5428d2b4-f00b-47fc-91a9-6825caa723b6.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5428d2b4-f00b-47fc-91a9-6825caa723b6</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Today, I was super-dad AND got a lot of coding done, and I managed to get my useful
links controls done for my site <a href="http://www.rubiconcomputing.com/DevArea.aspx" target="_blank">here</a>.
It was actually a complex process to get things like the webthumbs integrated, update
the activity aggregator, create an admin page. The end result needs some cleanup,
but I think for a first run, it came out nice. Tomorrow I will blog on the details
and some code on how I did everything in case someone decides they want something
similar.
</p>
        <p>
Tonight, I am tired. But as I was coding, I came across some code for accessing my
webthumbs, and something struck me. In .Net 3.5, there's a new keyword "var" which
allows for anonymous casting (sort of). When it compiles, the underlying code is cast
to the correct type, and in using the var typed variable, it acts like the cast-type.
It would definitely speed up development if you used it a lot. For those old-school
VB fans, it really reminds me of the variant data type (which it is not). Read more
about it <a href="http://msdn.microsoft.com/en-us/library/bb383973.aspx" target="_blank">here </a>if
you want some details.
</p>
        <p>
However, as with all things, there is a cost. For me, it's readability. In English
anyways, we read left to right. When I see a "var" vast variable, I have to keep reading
to understand the type, then see how it is used. Not too difficult (unless it is coming
out of a function or LINQ query), but it does take a little more time to figure it
out. For example..
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> doc = <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">XDocument</span>(
</p>
          <p style="MARGIN: 0px">
                <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">XElement</span>(
</p>
        </div>
        <!--EndFragment-->
        <p>
That being said, you can get around using it by declaring the variable to the
expected type when you code it. I have some samples I will post later when I was using
LINQ I forced myself to do this so I would fully understand what was happening in
my LINQ. <a href="http://richarddingwall.name/2008/06/21/csharps-var-keyword-jeff-atwood-gets-it-all-wrong/" target="_blank">Here's</a> someone
else who is taking a similar take on it.
</p>
        <p>
Anyone have any thoughts on that?
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=5428d2b4-f00b-47fc-91a9-6825caa723b6" />
      </body>
      <title>WebThumbs working.. but an aside about VS.Net 2008's var keyword</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,5428d2b4-f00b-47fc-91a9-6825caa723b6.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/23/WebThumbsWorkingButAnAsideAboutVSNet2008sVarKeyword.aspx</link>
      <pubDate>Sun, 23 Aug 2009 06:09:25 GMT</pubDate>
      <description>&lt;p&gt;
Today, I was super-dad AND got a lot of coding done, and I managed to get my useful
links controls done for my site &lt;a href="http://www.rubiconcomputing.com/DevArea.aspx" target=_blank&gt;here&lt;/a&gt;.
It was actually a complex process to get things like the webthumbs integrated, update
the activity aggregator, create an admin page. The end result needs some cleanup,
but I think for a first run, it came out nice. Tomorrow I will blog on the details
and some code on how I did everything in case someone decides they want something
similar.
&lt;/p&gt;
&lt;p&gt;
Tonight, I am tired. But as I was coding, I came across some code for accessing my
webthumbs, and something struck me. In .Net 3.5, there's a new keyword "var" which
allows for anonymous casting (sort of). When it compiles, the underlying code is cast
to the correct type, and in using the var typed variable, it acts like the cast-type.
It would definitely speed up development if you used it a lot. For those old-school
VB fans, it really reminds me of the variant data type (which it is not). Read more
about it &lt;a href="http://msdn.microsoft.com/en-us/library/bb383973.aspx" target=_blank&gt;here &lt;/a&gt;if
you want some details.
&lt;/p&gt;
&lt;p&gt;
However, as with all things, there is a cost. For me, it's readability. In English
anyways, we read left to right. When I see a "var" vast variable, I have to keep reading
to understand the type, then see how it is used. Not too difficult (unless it is coming
out of a function or LINQ query), but it does take a little more time to figure it
out. For example..
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; doc = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt;(
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;XElement&lt;/span&gt;(
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
That being said, you can get around using it by&amp;nbsp;declaring the variable to the
expected type when you code it. I have some samples I will post later when I was using
LINQ I forced myself to do this so I would fully understand what was happening in
my LINQ. &lt;a href="http://richarddingwall.name/2008/06/21/csharps-var-keyword-jeff-atwood-gets-it-all-wrong/" target=_blank&gt;Here's&lt;/a&gt; someone
else who is taking a similar take on it.
&lt;/p&gt;
&lt;p&gt;
Anyone have any thoughts on that?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=5428d2b4-f00b-47fc-91a9-6825caa723b6" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,5428d2b4-f00b-47fc-91a9-6825caa723b6.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=80361cb8-d014-4cc3-b122-202c9f889e92</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,80361cb8-d014-4cc3-b122-202c9f889e92.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,80361cb8-d014-4cc3-b122-202c9f889e92.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=80361cb8-d014-4cc3-b122-202c9f889e92</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font face="Calibri" color="#000000" size="3">Here’s another question which is very
basic, and is mandatory to be able to answer for C# developers: </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>Question</b>: What are
the various access modifiers in C#?</font>
            </font>
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>
                </b>
              </font>
            </font>
          </font> 
</p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>Answer: </b>public, private,
protected, internal, protected internal</font>
            </font>
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font face="Calibri" color="#000000" size="3">Depending on how the person answers
the question (e.g. if it’s obviously an easy question for them, I move on), I may
follow up with “So what does the protected keyword mean?”</font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font face="Calibri" color="#000000" size="3">So here’s the answers to each… you absolutely
need to know what each of these are!</font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>Public</b> – accessible
to anything </font>
            </font>
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>Private</b> – can only
be access by code in the same class or struct</font>
            </font>
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>Internal</b> – accessible
only within the same assembly</font>
            </font>
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font size="3">
            <font color="#000000">
              <font face="Calibri">
                <b>Protected</b> – accessible
in the same class, or in a derived class</font>
            </font>
          </font>
        </p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font face="Calibri" color="#000000" size="3">
          </font> 
</p>
        <p class="MsoNormal" style="MARGIN: 0in 0in 0pt">
          <font face="Calibri" color="#000000" size="3">Go here for some more info if needed:  </font>
          <a href="http://msdn.microsoft.com/en-us/library/ms173121.aspx" target="_blank">
            <font face="Calibri" size="3">http://msdn.microsoft.com/en-us/library/ms173121.aspx</font>
          </a>
          <font face="Calibri" color="#000000" size="3">
          </font>
        </p>
        <p>
        </p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=80361cb8-d014-4cc3-b122-202c9f889e92" />
      </body>
      <title>Tip of the Day: Interview Questions- Access modifiers in C#         </title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,80361cb8-d014-4cc3-b122-202c9f889e92.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/21/TipOfTheDayInterviewQuestionsAccessModifiersInC.aspx</link>
      <pubDate>Fri, 21 Aug 2009 04:06:04 GMT</pubDate>
      <description>&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Here’s another question which is very basic,
and is mandatory to be able to answer for C# developers: &lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;Question&lt;/b&gt;: What are the
various access modifiers in C#?&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;&lt;/b&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;Answer: &lt;/b&gt;public, private,
protected, internal, protected internal&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Depending on how the person answers the question
(e.g. if it’s obviously an easy question for them, I move on), I may follow up with
“So what does the protected keyword mean?”&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;So here’s the answers to each… you absolutely
need to know what each of these are!&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;Public&lt;/b&gt; – accessible to
anything &lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;Private&lt;/b&gt; – can only be access
by code in the same class or struct&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;Internal&lt;/b&gt; – accessible only
within the same assembly&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font size=3&gt;&lt;font color=#000000&gt;&lt;font face=Calibri&gt;&lt;b&gt;Protected&lt;/b&gt; – accessible
in the same class, or in a derived class&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;&lt;/font&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p class=MsoNormal style="MARGIN: 0in 0in 0pt"&gt;
&lt;font face=Calibri color=#000000 size=3&gt;Go here for some more info if needed:&amp;nbsp; &lt;/font&gt;&lt;a href="http://msdn.microsoft.com/en-us/library/ms173121.aspx" target=_blank&gt;&lt;font face=Calibri size=3&gt;http://msdn.microsoft.com/en-us/library/ms173121.aspx&lt;/font&gt;&lt;/a&gt;&lt;font face=Calibri color=#000000 size=3&gt; &lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=80361cb8-d014-4cc3-b122-202c9f889e92" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,80361cb8-d014-4cc3-b122-202c9f889e92.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=e9eb693b-4bfb-464c-bbac-11053bfe6e8e</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,e9eb693b-4bfb-464c-bbac-11053bfe6e8e.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,e9eb693b-4bfb-464c-bbac-11053bfe6e8e.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=e9eb693b-4bfb-464c-bbac-11053bfe6e8e</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I needed to use LINQ to XML to grab some RSS feed information into a BusinessObject
I created to save to a database. Here's what I needed:
</p>
        <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">var</span> activityList = <span style="COLOR: blue">from</span> e <span style="COLOR: blue">in</span> doc.Descendants(<span style="COLOR: #a31515">"item"</span>)
</p>
          <p style="MARGIN: 0px">
                   
                   <span style="COLOR: blue">select</span><span style="COLOR: blue">new</span> RubiconPortal.BusinessObjects.<span style="COLOR: #2b91af">Activity</span></p>
          <p style="MARGIN: 0px">
                   
                  
{
</p>
          <p style="MARGIN: 0px">
                   
                   
   ActivityTypeID = <span style="COLOR: #2b91af">ActivityTypes</span>.Blog.Code,
</p>
          <p style="MARGIN: 0px">
                   
                   
   ActivityDate = e.Element(<span style="COLOR: #a31515">"pubDate"</span>).Value.RSSDateTime().ToShortDateString()
+ <span style="COLOR: #a31515">" "</span> + e.Element(<span style="COLOR: #a31515">"pubDate"</span>).Value.RSSDateTime().ToShortDateString(),
</p>
          <p style="MARGIN: 0px">
                   
                   
   ActivitySummary = <span style="COLOR: #2b91af">HttpUtility</span>.HtmlDecode(e.Element(<span style="COLOR: #a31515">"title"</span>).Value),
</p>
          <p style="MARGIN: 0px">
                   
                   
   ActivityDetailsURL = e.Element(<span style="COLOR: #a31515">"link"</span>).Value
</p>
          <p style="MARGIN: 0px">
                   
                  
};
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <font face="Verdana" size="2">Since the pubDate comes across in a format which is
different than I wanted, I decided to write an extension method called RSSDateTime()
to convert to a DateTime, from which I can format any way I want or work with. Here's
the method:</font>
          </p>
          <p style="MARGIN: 0px">
 
</p>
          <div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
            <p style="MARGIN: 0px">
              <span style="COLOR: blue">public</span>
              <span style="COLOR: blue">static</span>
              <span style="COLOR: #2b91af">DateTime</span> RSSDateTime(<span style="COLOR: blue">this</span><span style="COLOR: blue">string</span> date)
</p>
            <p style="MARGIN: 0px">
        {
</p>
            <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">DateTime</span> d;
</p>
            <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> (<span style="COLOR: #2b91af">DateTime</span>.TryParse(date, <span style="COLOR: blue">out</span> d))
</p>
            <p style="MARGIN: 0px">
            {
</p>
            <p style="MARGIN: 0px">
                <span style="COLOR: blue">return</span><span style="COLOR: #2b91af">Convert</span>.ToDateTime(date);
</p>
            <p style="MARGIN: 0px">
            }
</p>
            <p style="MARGIN: 0px">
 
</p>
            <p style="MARGIN: 0px">
            <span style="COLOR: blue">return</span><span style="COLOR: #2b91af">DateTime</span>.Now;
</p>
            <p style="MARGIN: 0px">
 
</p>
            <p style="MARGIN: 0px">
        }
</p>
          </div>
          <!--EndFragment-->
        </div>
        <!--EndFragment-->
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=e9eb693b-4bfb-464c-bbac-11053bfe6e8e" />
      </body>
      <title>Tip of the Day: Creating an Extension method to convert RSS pubDate to DateTime</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,e9eb693b-4bfb-464c-bbac-11053bfe6e8e.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/15/TipOfTheDayCreatingAnExtensionMethodToConvertRSSPubDateToDateTime.aspx</link>
      <pubDate>Sat, 15 Aug 2009 20:18:49 GMT</pubDate>
      <description>&lt;p&gt;
I needed to use LINQ to XML to grab some RSS feed information into a BusinessObject
I created to save to a database. Here's what I needed:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;var&lt;/span&gt; activityList = &lt;span style="COLOR: blue"&gt;from&lt;/span&gt; e &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; doc.Descendants(&lt;span style="COLOR: #a31515"&gt;"item"&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;select&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; RubiconPortal.BusinessObjects.&lt;span style="COLOR: #2b91af"&gt;Activity&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; ActivityTypeID = &lt;span style="COLOR: #2b91af"&gt;ActivityTypes&lt;/span&gt;.Blog.Code,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; ActivityDate = e.Element(&lt;span style="COLOR: #a31515"&gt;"pubDate"&lt;/span&gt;).Value.RSSDateTime().ToShortDateString()
+ &lt;span style="COLOR: #a31515"&gt;" "&lt;/span&gt; + e.Element(&lt;span style="COLOR: #a31515"&gt;"pubDate"&lt;/span&gt;).Value.RSSDateTime().ToShortDateString(),
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; ActivitySummary = &lt;span style="COLOR: #2b91af"&gt;HttpUtility&lt;/span&gt;.HtmlDecode(e.Element(&lt;span style="COLOR: #a31515"&gt;"title"&lt;/span&gt;).Value),
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; ActivityDetailsURL = e.Element(&lt;span style="COLOR: #a31515"&gt;"link"&lt;/span&gt;).Value
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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;
};
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;font face=Verdana size=2&gt;Since the pubDate comes across in a format which is different
than I wanted, I decided to write an extension method called RSSDateTime() to convert
to a DateTime, from which I can format any way I want or work with. Here's the method:&lt;/font&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;div style="FONT-SIZE: 8pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DateTime&lt;/span&gt; RSSDateTime(&lt;span style="COLOR: blue"&gt;this&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; date)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: #2b91af"&gt;DateTime&lt;/span&gt; d;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;DateTime&lt;/span&gt;.TryParse(date, &lt;span style="COLOR: blue"&gt;out&lt;/span&gt; d))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;Convert&lt;/span&gt;.ToDateTime(date);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;DateTime&lt;/span&gt;.Now;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=e9eb693b-4bfb-464c-bbac-11053bfe6e8e" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,e9eb693b-4bfb-464c-bbac-11053bfe6e8e.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=308bd3f2-4d3c-48b6-84f2-1dbe04982eed</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,308bd3f2-4d3c-48b6-84f2-1dbe04982eed.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,308bd3f2-4d3c-48b6-84f2-1dbe04982eed.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=308bd3f2-4d3c-48b6-84f2-1dbe04982eed</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have to get some landscape rock put out before my home owner's association has a
cow, but I decided to do some more work on my activity aggregator. Today, I decided
to integrate my blog feed into it, so when I post here, it will automatically update
this activity on my home page (and soon to be in my developer's area).
</p>
        <p>
Here's what the end result looks (for now).
</p>
        <p>
          <img src="http://www.dotnettechnologies.com/content/binary/DevArea.png" border="0" />
        </p>
        <p>
Doing it was fairly easy with the design I implemented in my last <a href="http://www.dotnettechnologies.com/PermaLink,guid,058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1.aspx" target="_blank">post</a>.
My BlogFeed class inherits the BaseFeed class, which means I need to implement the
ParseFeed() method. Since the RSS feed from my blog is XML, I was easily able to adapt the
same code from my TwitterFeed class to work for this RSS feed (which should actually
work for any RSS feed I pass in).
</p>
        <p>
I also created another Extension method (for practice) to convert the RSS feed date
time to a C# DateTime object. I will post that code as "Tip of the Day" but I have
to give Dan Wahlin <a href="http://weblogs.asp.net/dwahlin/archive/2006/09/28/Creating-an-ASP.NET-RSS-Blog-Roller.aspx" target="_blank">credit</a> for
it, as I adapted some sample code he provided.
</p>
        <p>
Here's how the RSS feed (aka BlogFeed) uses LINQ to XML for creating my activity object.
</p>
        <div style="FONT-SIZE: 7pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <span style="COLOR: #2b91af">
            <div style="FONT-SIZE: 7pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
    <span style="COLOR: blue">internal</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">BlogFeed</span> : <span style="COLOR: #2b91af">BaseFeed</span></p>
              <p style="MARGIN: 0px">
    {
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
        <span style="COLOR: blue">public</span><span style="COLOR: blue">override</span><span style="COLOR: blue">int</span> ParseFeed(<span style="COLOR: #2b91af">XDocument</span> doc)
</p>
              <p style="MARGIN: 0px">
        {
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">try</span></p>
              <p style="MARGIN: 0px">
            {
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">ReturnCode</span> code
= <span style="COLOR: #2b91af">ReturnCode</span>.Success;
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">if</span> (doc
!= <span style="COLOR: blue">null</span>)
</p>
              <p style="MARGIN: 0px">
                {
</p>
              <p style="MARGIN: 0px">
                    <span style="COLOR: blue">var</span> activityList
= <span style="COLOR: blue">from</span> e <span style="COLOR: blue">in</span> doc.Descendants(<span style="COLOR: #a31515">"item"</span>)
</p>
              <p style="MARGIN: 0px">
                   
                   <span style="COLOR: blue">select</span><span style="COLOR: blue">new</span> RubiconPortal.BusinessObjects.<span style="COLOR: #2b91af">Activity</span></p>
              <p style="MARGIN: 0px">
                   
                  
{
</p>
              <p style="MARGIN: 0px">
                   
                   
   ActivityTypeID = <span style="COLOR: #2b91af">ActivityTypes</span>.Blog.Code,
</p>
              <p style="MARGIN: 0px">
                   
                   
   ActivityDate = e.Element(<span style="COLOR: #a31515">"pubDate"</span>).Value.RSSDateTime().ToShortDateString()
+ <span style="COLOR: #a31515">" "</span> + e.Element(<span style="COLOR: #a31515">"pubDate"</span>).Value.RSSDateTime().ToShortDateString(),
</p>
              <p style="MARGIN: 0px">
                   
                   
   ActivitySummary = <span style="COLOR: #2b91af">HttpUtility</span>.HtmlDecode(e.Element(<span style="COLOR: #a31515">"title"</span>).Value),
</p>
              <p style="MARGIN: 0px">
                   
                   
   ActivityDetailsURL = e.Element(<span style="COLOR: #a31515">"link"</span>).Value
</p>
              <p style="MARGIN: 0px">
                   
                  
};
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
                    <span style="COLOR: blue">foreach</span> (<span style="COLOR: #2b91af">Activity</span> item <span style="COLOR: blue">in</span> activityList)
</p>
              <p style="MARGIN: 0px">
                   
{
</p>
              <p style="MARGIN: 0px">
                   
    <span style="COLOR: green">//We need to check and see if the item
exists</span></p>
              <p style="MARGIN: 0px">
                   
    <span style="COLOR: blue">if</span> (!<span style="COLOR: #2b91af">Activity</span>.CheckEntryExists(item.ActivityTypeID,
item.ActivityDetailsURL))
</p>
              <p style="MARGIN: 0px">
                   
    {
</p>
              <p style="MARGIN: 0px">
                   
        <span style="COLOR: blue">int</span> results
= item.Save();
</p>
              <p style="MARGIN: 0px">
                   
        <span style="COLOR: blue">if</span> (results
!= <span style="COLOR: #2b91af">ReturnCode</span>.Success.Code)
</p>
              <p style="MARGIN: 0px">
                   
            code = <span style="COLOR: #2b91af">ReturnCode</span>.Failure;
</p>
              <p style="MARGIN: 0px">
                   
    }
</p>
              <p style="MARGIN: 0px">
                   
    <span style="COLOR: blue">else</span></p>
              <p style="MARGIN: 0px">
                   
        <span style="COLOR: blue">return</span> code.Code;   <span style="COLOR: green">//we
can break once we hit one we've already logged (for performance reasons</span></p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
                   
}
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
                }
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">return</span> code.Code;
</p>
              <p style="MARGIN: 0px">
            }
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">catch</span> (<span style="COLOR: #2b91af">Exception</span> ex)
</p>
              <p style="MARGIN: 0px">
            {
</p>
              <p style="MARGIN: 0px">
                ErrorHandler(ex, <span style="COLOR: #a31515">"An
unexpected error occurred in TwitterFeed.ParseFeed() - "</span> + ex.Message);
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">return</span><span style="COLOR: #2b91af">ReturnCode</span>.Failure.Code;
</p>
              <p style="MARGIN: 0px">
            }
</p>
              <p style="MARGIN: 0px">
        }
</p>
              <p style="MARGIN: 0px">
    }
</p>
              <p style="MARGIN: 0px">
 
</p>
            </div>
            <!--EndFragment-->
            <p style="MARGIN: 0px">
              <!--EndFragment-->
            </p>
          </span>
          <font face="Verdana" size="2">My next step will be to integrate some AJAX
so when the user hovers over the link, they can see things like the date, more of
the topic, etc. I also need to integrate my "Useful Links" dicussion as well.</font>
        </div>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=308bd3f2-4d3c-48b6-84f2-1dbe04982eed" />
      </body>
      <title>Logging Blog Activity to my Activity Aggregator</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,308bd3f2-4d3c-48b6-84f2-1dbe04982eed.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/15/LoggingBlogActivityToMyActivityAggregator.aspx</link>
      <pubDate>Sat, 15 Aug 2009 20:13:22 GMT</pubDate>
      <description>&lt;p&gt;
I have to get some landscape rock put out before my home owner's association has a
cow, but I decided to do some more work on my activity aggregator. Today, I decided
to integrate my blog feed into it, so when I post here, it will automatically update
this activity on my home page (and soon to be in my developer's area).
&lt;/p&gt;
&lt;p&gt;
Here's what the end result looks (for now).
&lt;/p&gt;
&lt;p&gt;
&lt;img src="http://www.dotnettechnologies.com/content/binary/DevArea.png" border=0&gt;
&lt;/p&gt;
&lt;p&gt;
Doing it was fairly easy with the design I implemented in my last &lt;a href="http://www.dotnettechnologies.com/PermaLink,guid,058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1.aspx" target=_blank&gt;post&lt;/a&gt;.
My BlogFeed class inherits the BaseFeed class, which means I need to implement the
ParseFeed() method. Since the RSS feed from my blog is XML, I was easily able to adapt&amp;nbsp;the
same code from my TwitterFeed class to work for this RSS feed (which should actually
work for any RSS feed I pass in).
&lt;/p&gt;
&lt;p&gt;
I also created another Extension method (for practice) to convert the RSS feed date
time to a C# DateTime object. I will post that code as "Tip of the Day" but I have
to give Dan Wahlin &lt;a href="http://weblogs.asp.net/dwahlin/archive/2006/09/28/Creating-an-ASP.NET-RSS-Blog-Roller.aspx" target=_blank&gt;credit&lt;/a&gt; for
it, as I adapted some sample code he provided.
&lt;/p&gt;
&lt;p&gt;
Here's how the RSS feed (aka BlogFeed) uses LINQ to XML for creating my activity object.
&lt;/p&gt;
&lt;div style="FONT-SIZE: 7pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: #2b91af"&gt; 
&lt;div style="FONT-SIZE: 7pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;BlogFeed&lt;/span&gt; : &lt;span style="COLOR: #2b91af"&gt;BaseFeed&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ParseFeed(&lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt; doc)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: #2b91af"&gt;ReturnCode&lt;/span&gt; code
= &lt;span style="COLOR: #2b91af"&gt;ReturnCode&lt;/span&gt;.Success;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (doc
!= &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; activityList
= &lt;span style="COLOR: blue"&gt;from&lt;/span&gt; e &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; doc.Descendants(&lt;span style="COLOR: #a31515"&gt;"item"&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;select&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; RubiconPortal.BusinessObjects.&lt;span style="COLOR: #2b91af"&gt;Activity&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; ActivityTypeID = &lt;span style="COLOR: #2b91af"&gt;ActivityTypes&lt;/span&gt;.Blog.Code,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; ActivityDate = e.Element(&lt;span style="COLOR: #a31515"&gt;"pubDate"&lt;/span&gt;).Value.RSSDateTime().ToShortDateString()
+ &lt;span style="COLOR: #a31515"&gt;" "&lt;/span&gt; + e.Element(&lt;span style="COLOR: #a31515"&gt;"pubDate"&lt;/span&gt;).Value.RSSDateTime().ToShortDateString(),
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; ActivitySummary = &lt;span style="COLOR: #2b91af"&gt;HttpUtility&lt;/span&gt;.HtmlDecode(e.Element(&lt;span style="COLOR: #a31515"&gt;"title"&lt;/span&gt;).Value),
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; ActivityDetailsURL = e.Element(&lt;span style="COLOR: #a31515"&gt;"link"&lt;/span&gt;).Value
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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;
};
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;Activity&lt;/span&gt; item &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; activityList)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: green"&gt;//We need to check and see if the item
exists&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (!&lt;span style="COLOR: #2b91af"&gt;Activity&lt;/span&gt;.CheckEntryExists(item.ActivityTypeID,
item.ActivityDetailsURL))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; results
= item.Save();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (results
!= &lt;span style="COLOR: #2b91af"&gt;ReturnCode&lt;/span&gt;.Success.Code)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; code = &lt;span style="COLOR: #2b91af"&gt;ReturnCode&lt;/span&gt;.Failure;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;else&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; code.Code;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: green"&gt;//we
can break once we hit one we've already logged (for performance reasons&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; code.Code;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;Exception&lt;/span&gt; ex)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; ErrorHandler(ex, &lt;span style="COLOR: #a31515"&gt;"An
unexpected error occurred in TwitterFeed.ParseFeed() - "&lt;/span&gt; + ex.Message);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;ReturnCode&lt;/span&gt;.Failure.Code;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;!--EndFragment--&gt;
&lt;/span&gt;&lt;font face=Verdana size=2&gt;My next step will be to integrate some AJAX so when
the user hovers over the link, they can see things like the date, more of the topic,
etc. I also need to integrate my "Useful Links" dicussion as well.&lt;/font&gt;&gt;
&lt;/div&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=308bd3f2-4d3c-48b6-84f2-1dbe04982eed" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,308bd3f2-4d3c-48b6-84f2-1dbe04982eed.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Tonight was a very enjoyable night of coding. I created the first phase of my "activity
aggregator". I actually had a more clever name for it, but being tired, it slips my
mind right now.
</p>
        <p>
Currently, I post several places.. short updates for on Twitter. Longer discussions
end up on here, my blog. I have some other sources I plan on integrating over time,
such as links I found useful (similar to Digg, but also where I can place why I found
it useful). That means growth, and when it comes to design, it's best to design change
into it up front.
</p>
        <p>
The first thing I needed to do was create my table and business object to collect
these activities. In my table, I store ActivityDate, what type of activity it was
(foreign key to another table -- ActivityType), a brief summary of the activity text,
and finally the url someone interested could click on to get more information. The
internal members of my activity class look like this:
</p>
        <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   15</span> <span style="COLOR: blue">   
    #region</span> Private Members
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   16</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   17</span>         <span style="COLOR: blue">private</span><span style="COLOR: blue">int</span> activityID;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   18</span>         <span style="COLOR: blue">private</span><span style="COLOR: blue">int</span> activityTypeID;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   19</span>         <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> activityDate;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   20</span>         <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> activitySummary;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   21</span>         <span style="COLOR: blue">private</span><span style="COLOR: blue">string</span> activityDetailsURL;
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   22</span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: #2b91af">   23</span> <span style="COLOR: blue">   
    #endregion</span></p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">Each private member
has a publically exposed property.</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">Most of my activities
will have XML feeds, such as the RSS feed of my blog, and the Twitter API. Therefore,
I enforce a similar implementation by creating an abstract base class, called BaseFeed,
which looks like this:</font>
            </span>
          </p>
          <span style="COLOR: blue">
            <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    1</span> <span style="COLOR: blue">using</span> System.Xml.Linq;
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    2</span> <span style="COLOR: blue">using</span> RubiconPortal.Common;
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    3</span> 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    4</span> <span style="COLOR: blue">namespace</span> RubiconPortal.BusinessObjects
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    5</span> {
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    6</span>     <span style="COLOR: blue">internal</span><span style="COLOR: blue">abstract</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">BaseFeed</span> :
BaseClass
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    7</span>    
{
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    8</span> 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">    9</span>    
    <span style="COLOR: blue">public</span><span style="COLOR: blue">abstract</span><span style="COLOR: blue">int</span> ParseFeed(XDocument
doc);
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   10</span> 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   11</span>     }
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   12</span> }
</p>
            </div>
            <!--EndFragment-->
          </span>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">So now I have a "contract"
that I need to use to have a similar method for any activity I want to log. I could
have used an interface for this, since there's no true implentation here, and I may
refactor it later to do so, but I do have some ideas where I may want to provide some
implementation, so that's why I chose an abstract class.</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">So the first item I
wanted to do was implement capturing my <a href="http://twitter.com/RubiconComp" target="_blank">Twitter
posts</a> in this activity, since I currently don't have a way to capture and post
them on my site. I will add the rest of the activities later. In a previous post,
I described how I took the Yedda Twitter API and modified it to return XDocuments,
and here's another chance to take advantage of that change with LINQ.</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">When I post to my Twitter
feed, I want to make sure my home page automatically reflects this activity. So I
implement a TwitterFeed object, which implements the BaseFeed method ParseFeed. Using
LINQ to XML, I pull out the pieces of the response I want, and populate the public
properties of my Activities class, then save my activity. Here's what my TwitterFeed
class looks like:</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <span style="COLOR: blue">
            <font face="Verdana" color="#000000">
              <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    1</span> <span style="COLOR: blue">using</span> System;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    2</span> <span style="COLOR: blue">using</span> System.Linq;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    3</span> <span style="COLOR: blue">using</span> System.Web;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    4</span> <span style="COLOR: blue">using</span> System.Xml.Linq;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    5</span> <span style="COLOR: blue">using</span> Rubicon.Common;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    6</span> <span style="COLOR: blue">using</span> RubiconPortal.Common;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    7</span> 
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    8</span> <span style="COLOR: blue">namespace</span> RubiconPortal.BusinessObjects
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">    9</span> {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   10</span>     <span style="COLOR: blue">internal</span><span style="COLOR: blue">class</span><span style="COLOR: #2b91af">TwitterFeed</span> :
BaseFeed
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   11</span>     {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   12</span>         <span style="COLOR: blue">public</span><span style="COLOR: blue">override</span><span style="COLOR: blue">int</span> ParseFeed(XDocument
doc)
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   13</span>        
{
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   14</span>        
    <span style="COLOR: blue">try</span></p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   15</span>        
    {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   16</span>        
        <span style="COLOR: blue">if</span> (doc != <span style="COLOR: blue">null</span>)
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   17</span>        
        {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   18</span>        
            <span style="COLOR: blue">var</span> activityList
= <span style="COLOR: blue">from</span> e <span style="COLOR: blue">in</span> doc.Descendants(<span style="COLOR: #a31515">"status"</span>)
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   19</span>        
                   
           <span style="COLOR: blue">select</span><span style="COLOR: blue">new</span> RubiconPortal.BusinessObjects.Activity
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   20</span>        
                   
           {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   21</span>        
                   
               ActivityTypeID
= ActivityTypes.Twitter.Code,
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   22</span>        
                   
               ActivityDate
= (e.Element(<span style="COLOR: #a31515">"created_at"</span>).Value.ParseDateTime()).ToShortDateString()
+ <span style="COLOR: #a31515">" "</span> + (e.Element(<span style="COLOR: #a31515">"created_at"</span>).Value.ParseDateTime()).ToShortTimeString(),
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   23</span>        
                   
               ActivitySummary
= HttpUtility.HtmlDecode(e.Element(<span style="COLOR: #a31515">"text"</span>).Value),
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   24</span>        
                   
               ActivityDetailsURL
= <span style="COLOR: #a31515">"http://twitter.com/"</span> + e.Element(<span style="COLOR: #a31515">"user"</span>).Element(<span style="COLOR: #a31515">"screen_name"</span>).Value
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   25</span>        
                   
           };
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   26</span> 
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   27</span>        
            <span style="COLOR: blue">foreach</span> (RubiconPortal.BusinessObjects.Activity
item <span style="COLOR: blue">in</span> activityList)
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   28</span>        
            {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   29</span>        
                item.Save();
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   30</span>        
            }
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   31</span>        
        }
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   32</span> 
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   33</span>        
        <span style="COLOR: blue">return</span> ReturnCode.Success.Code;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   34</span>        
    }
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   35</span>        
    <span style="COLOR: blue">catch</span> (<span style="COLOR: #2b91af">Exception</span> ex)
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   36</span>        
    {
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   37</span>        
        ErrorHandler(ex, <span style="COLOR: #a31515">"An
unexpected error occurred in TwitterFeed.ParseFeed() - "</span> + ex.Message);
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   38</span>        
        <span style="COLOR: blue">return</span> ReturnCode.Failure.Code;
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   39</span>        
    } 
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   40</span>        
}
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   41</span> 
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   42</span>     }
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   43</span> 
</p>
                <p style="MARGIN: 0px">
                  <span style="COLOR: #2b91af">   44</span> }
</p>
              </div>
              <!--EndFragment-->
            </font>
          </span>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">Within the ParseFeed
method I am using LINQ to XML to populate my business object calling the save()
method to write it to the database. As you can see, using LINQ to XML can be
a lot simpler than using XML/XPath. Once in the database, I can query it in my user
control, and display it on my home page <a href="http://www.rubiconcomputing.com/" target="_blank">here</a>.</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">Now, when I make my
Twitter post, all I need to do is take the XDocument the Twitter API returns, and
pass it into the ParseFeed method, which looks like this...</font>
            </span>
          </p>
          <span style="COLOR: blue">
            <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   35</span>        
            <span style="COLOR: green">//Post
my tweet to Twitter</span></p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   36</span>        
            TwitterAPI twit = <span style="COLOR: blue">new</span> TwitterAPI();
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   37</span>        
            XDocument doc = twit.UpdateAsXML(Settings.TwitterUserName(),
Settings.TwitterPassword(), txtPost.Text);
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   38</span> 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   39</span>        
            <span style="COLOR: green">//Save
it to the activity table for displaying the activity</span></p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   40</span>        
            TwitterFeed feed = <span style="COLOR: blue">new</span> TwitterFeed();
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">   41</span>        
            feed.ParseFeed(doc);
</p>
            </div>
            <!--EndFragment-->
          </span>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">Simple and neat! Now
when I implement it for my blog, it will be just as quick and easy!</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">Props go out to this <a href="http://blogs.msdn.com/bursteg/archive/2009/05/29/twitter-api-from-c-getting-a-user-s-time-line.aspx" target="_blank">post </a>I
snagged an extension method for formatting the Twitter posting date to something a
human can use (and my C# class can use to manipulate and save!)</font>
            </span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">
              <font face="Verdana" color="#000000">
              </font>
            </span> 
</p>
        </div>
        <!--EndFragment-->
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1" />
      </body>
      <title>Creating my activity aggregator</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/14/CreatingMyActivityAggregator.aspx</link>
      <pubDate>Fri, 14 Aug 2009 06:40:31 GMT</pubDate>
      <description>&lt;p&gt;
Tonight was a very enjoyable night of coding. I created the first phase of my "activity
aggregator". I actually had a more clever name for it, but being tired, it slips my
mind right now.
&lt;/p&gt;
&lt;p&gt;
Currently, I post several places.. short updates for on Twitter. Longer discussions
end up on here, my blog. I have some other sources I plan on integrating over time,
such as links I found useful (similar to Digg, but also where I can place why I found
it useful). That means growth, and when it comes to design, it's best to design change
into it up front.
&lt;/p&gt;
&lt;p&gt;
The first thing I needed to do was create my table and business object to collect
these activities. In my table, I store ActivityDate, what type of activity it was
(foreign key to another table -- ActivityType), a brief summary of the activity text,
and finally the url someone interested could click on to get more information. The
internal members of my activity class look like this:
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;15&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #region&lt;/span&gt; Private Members
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;16&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;17&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; activityID;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;18&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; activityTypeID;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;19&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; activityDate;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;20&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; activitySummary;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;21&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;private&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; activityDetailsURL;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;22&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;23&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; #endregion&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;Each private member has
a publically exposed property.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;Most of my activities will
have XML feeds, such as the RSS feed of my blog, and the Twitter API. Therefore, I
enforce a similar implementation by creating an abstract base class, called BaseFeed,
which looks like this:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="COLOR: blue"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Xml.Linq;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; RubiconPortal.Common;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; RubiconPortal.BusinessObjects
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&lt;/span&gt;&amp;nbsp;{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;BaseFeed&lt;/span&gt; :
BaseClass
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;9&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;abstract&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ParseFeed(XDocument
doc);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;10&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;11&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;12&lt;/span&gt;&amp;nbsp;}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;So now I have a "contract"
that I need to use to have a similar method for any activity I want to log. I could
have used an interface for this, since there's no true implentation here, and I may
refactor it later to do so, but I do have some ideas where I may want to provide some
implementation, so that's why I chose an abstract class.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;So the first item I wanted
to do was implement capturing my &lt;a href="http://twitter.com/RubiconComp" target=_blank&gt;Twitter
posts&lt;/a&gt; in this activity, since I currently don't have a way to capture and post
them on my site. I will add the rest of the activities later. In a previous post,
I described how I took the Yedda Twitter API and modified it to return XDocuments,
and here's another chance to take advantage of that change with LINQ.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;When I post to my Twitter
feed, I want to make sure my home page automatically reflects this activity. So I
implement a TwitterFeed object, which implements the BaseFeed method ParseFeed. Using
LINQ to XML, I pull out the pieces of the response I want, and populate the public
properties of my Activities class, then save my activity. Here's what my TwitterFeed
class looks like:&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;1&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;2&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Linq;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;3&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Web;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;4&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; System.Xml.Linq;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;5&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; Rubicon.Common;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;6&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;using&lt;/span&gt; RubiconPortal.Common;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;7&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;8&lt;/span&gt;&amp;nbsp;&lt;span style="COLOR: blue"&gt;namespace&lt;/span&gt; RubiconPortal.BusinessObjects
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;9&lt;/span&gt;&amp;nbsp;{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;10&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;internal&lt;/span&gt; &lt;span style="COLOR: blue"&gt;class&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;TwitterFeed&lt;/span&gt; :
BaseFeed
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;11&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;12&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;override&lt;/span&gt; &lt;span style="COLOR: blue"&gt;int&lt;/span&gt; ParseFeed(XDocument
doc)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;13&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;14&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;15&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;16&lt;/span&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; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (doc != &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;17&lt;/span&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; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;18&lt;/span&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; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; activityList
= &lt;span style="COLOR: blue"&gt;from&lt;/span&gt; e &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; doc.Descendants(&lt;span style="COLOR: #a31515"&gt;"status"&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;19&lt;/span&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; &lt;span style="COLOR: blue"&gt;select&lt;/span&gt; &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; RubiconPortal.BusinessObjects.Activity
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;20&lt;/span&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; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;21&lt;/span&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;&amp;nbsp; ActivityTypeID
= ActivityTypes.Twitter.Code,
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;22&lt;/span&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;&amp;nbsp; ActivityDate
= (e.Element(&lt;span style="COLOR: #a31515"&gt;"created_at"&lt;/span&gt;).Value.ParseDateTime()).ToShortDateString()
+ &lt;span style="COLOR: #a31515"&gt;" "&lt;/span&gt; + (e.Element(&lt;span style="COLOR: #a31515"&gt;"created_at"&lt;/span&gt;).Value.ParseDateTime()).ToShortTimeString(),
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;23&lt;/span&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;&amp;nbsp; ActivitySummary
= HttpUtility.HtmlDecode(e.Element(&lt;span style="COLOR: #a31515"&gt;"text"&lt;/span&gt;).Value),
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;24&lt;/span&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;&amp;nbsp; ActivityDetailsURL
= &lt;span style="COLOR: #a31515"&gt;"http://twitter.com/"&lt;/span&gt; + e.Element(&lt;span style="COLOR: #a31515"&gt;"user"&lt;/span&gt;).Element(&lt;span style="COLOR: #a31515"&gt;"screen_name"&lt;/span&gt;).Value
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;25&lt;/span&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; };
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;26&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;27&lt;/span&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; &lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (RubiconPortal.BusinessObjects.Activity
item &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; activityList)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;28&lt;/span&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; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;29&lt;/span&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; item.Save();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;30&lt;/span&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; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;31&lt;/span&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; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;32&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;33&lt;/span&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; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; ReturnCode.Success.Code;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;34&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;35&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt; (&lt;span style="COLOR: #2b91af"&gt;Exception&lt;/span&gt; ex)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;36&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;37&lt;/span&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; ErrorHandler(ex, &lt;span style="COLOR: #a31515"&gt;"An
unexpected error occurred in TwitterFeed.ParseFeed() - "&lt;/span&gt; + ex.Message);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;38&lt;/span&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; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; ReturnCode.Failure.Code;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;39&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; } 
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;40&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;41&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;42&lt;/span&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;43&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;44&lt;/span&gt;&amp;nbsp;}
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/font&gt;&lt;/span&gt; 
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;Within&amp;nbsp;the ParseFeed
method I am&amp;nbsp;using LINQ to XML to populate my business object calling the save()
method&amp;nbsp;to write it to the database. As you can see, using LINQ to XML can be
a lot simpler than using XML/XPath. Once in the database, I can query it in my user
control, and display it on my home page &lt;a href="http://www.rubiconcomputing.com/" target=_blank&gt;here&lt;/a&gt;.&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;Now, when I make my Twitter
post, all I need to do is take the XDocument the Twitter API returns, and pass it
into the ParseFeed method, which looks like this...&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;span style="COLOR: blue"&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;35&lt;/span&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; &lt;span style="COLOR: green"&gt;//Post
my tweet to Twitter&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;36&lt;/span&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; TwitterAPI twit = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; TwitterAPI();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;37&lt;/span&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; XDocument doc = twit.UpdateAsXML(Settings.TwitterUserName(),
Settings.TwitterPassword(), txtPost.Text);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;38&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;39&lt;/span&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; &lt;span style="COLOR: green"&gt;//Save
it to the activity table for displaying the activity&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;40&lt;/span&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; TwitterFeed feed = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; TwitterFeed();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;41&lt;/span&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; feed.ParseFeed(doc);
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/span&gt; 
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;Simple and neat! Now when
I implement it for my blog, it will be just as quick and easy!&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;Props go out to this &lt;a href="http://blogs.msdn.com/bursteg/archive/2009/05/29/twitter-api-from-c-getting-a-user-s-time-line.aspx" target=_blank&gt;post &lt;/a&gt;I
snagged an extension method for formatting the Twitter posting date to something a
human can use (and my C# class can use to manipulate and save!)&lt;/font&gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&lt;font face=Verdana color=#000000&gt;&lt;/font&gt;&lt;/span&gt;&amp;nbsp;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,058b6bdb-5cc4-470d-a4ff-3f7452a4a7b1.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=c0cbc280-544f-45b1-943c-3715fb32920c</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,c0cbc280-544f-45b1-943c-3715fb32920c.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,c0cbc280-544f-45b1-943c-3715fb32920c.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=c0cbc280-544f-45b1-943c-3715fb32920c</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Tonight was a short night of development, as my folks were in town as my dad needed
to go to the doctor. I did get some database work done, and my business objects done.
I use a hybrid of Rockford Lhotka's CSLA. I don't need all the functionality (such
as layers of undo) so I trimmed them back the amount of functionality I needed and
created CodeSmith templates to generate my classes. Let me just say I can code really
fast now. :) If you haven't taken a look at Lhotka's Business Objects book, I highly
recommend taking a look at them. I began using his concepts in VB, and they have proven
very reliable and scalable.
</p>
        <p>
QDJ: Do you use ORM's, and if so, what flavor do you like?
</p>
        <p>
I have to admit, I am not the biggest fan of the various ORMs I have tried. They do
serve a purpose though, but I have found most inflexible. I am currently using nHibernate,
and while they make themselves readily available to code generation, so far, it seems
like a lot of code. See my previous comments about another ORM I tried. My brother
uses it, and seems to be happy with it. I just thought the learning curve was very
steep, and the documentation was very lacking. I took a beating for that opinion.
:)
</p>
        <p>
So tonight, I want to post a couple of links I used today. Soon there will be a control
for this on the <a href="http://www.rubiconcomputing.com/" target="_blank">Rubicon
Computing</a> site, but until then, I will post them here.
</p>
        <p>
First, I referred to this before, but here's a site with a lot of good links to various
"cheat sheets". Some are really good and useful. You can find those <a href="http://john-sheehan.com/blog/net-cheat-sheets/" target="_blank">here</a>.
</p>
        <p>
Next, I found some neat add-ins for Visual Studio 2008. The first is the <a href="http://visualstudiogallery.msdn.microsoft.com/en-us/bea9ed59-8857-4032-9666-9af1c1a33969" target="_blank">Source
Code Power Toy</a>. It outlines your code in a treeview, which makes navigating your
code, especially in complex classes, very easy. Best of all, it's free! It's available
for VS2005 as well.
</p>
        <p>
I also installed the <a href="http://code.msdn.microsoft.com/PowerCommands" target="_blank">Power
Commands</a> for the VS 2008 IDE. It has some useful right-click functionality, such
as opening a command prompt, and opening the containing folder, and that's just a
small glimpse of what it can do. It seems to be well documented, and I look forward
to exploring all it's functionality. And best thing, this one is free too.
</p>
        <p>
I'll probably post some useful CodeSmith templates I created. I love <a href="http://www.codesmithtools.com/" target="_blank">CodeSmith</a>,
but sometimes it's tough to find out exactly how to do things, so I will spare the
world the trial-and-error where I can. In the current project I am working on, our
team saved 1,100+ hours, and over $50,000 dollars last month alone by generating nHibernate
code from the templates we created. Yeah, I earned my rate last month for sure. :)
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=c0cbc280-544f-45b1-943c-3715fb32920c" />
      </body>
      <title>Some neat things I found today...</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,c0cbc280-544f-45b1-943c-3715fb32920c.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/12/SomeNeatThingsIFoundToday.aspx</link>
      <pubDate>Wed, 12 Aug 2009 05:31:11 GMT</pubDate>
      <description>&lt;p&gt;
Tonight was a short night of development, as my folks were in town as my dad needed
to go to the doctor. I did get some database work done, and my business objects done.
I use a hybrid of Rockford Lhotka's CSLA. I don't need all the functionality (such
as layers of undo) so I trimmed them back the amount of functionality I needed and
created CodeSmith templates to generate my classes. Let me just say I can code really
fast now. :) If you haven't taken a look at Lhotka's Business Objects book, I highly
recommend taking a look at them. I began using his concepts in VB, and they have proven
very reliable and scalable.
&lt;/p&gt;
&lt;p&gt;
QDJ: Do you use ORM's, and if so, what flavor do you like?
&lt;/p&gt;
&lt;p&gt;
I have to admit, I am not the biggest fan of the various ORMs I have tried. They do
serve a purpose though, but I have found most inflexible. I am currently using nHibernate,
and while they make themselves readily available to code generation, so far, it seems
like a lot of code. See my previous comments about another ORM I tried. My brother
uses it, and seems to be happy with it. I just thought the learning curve was very
steep, and the documentation was very lacking. I took a beating for that opinion.
:)
&lt;/p&gt;
&lt;p&gt;
So tonight, I want to post a couple of links I used today. Soon there will be a control
for this on the&amp;nbsp;&lt;a href="http://www.rubiconcomputing.com/" target=_blank&gt;Rubicon
Computing&lt;/a&gt;&amp;nbsp;site, but until then, I will post them here.
&lt;/p&gt;
&lt;p&gt;
First, I referred to this before, but here's a site with a lot of good links to various
"cheat sheets". Some are really good and useful. You can find those &lt;a href="http://john-sheehan.com/blog/net-cheat-sheets/" target=_blank&gt;here&lt;/a&gt;.
&lt;/p&gt;
&lt;p&gt;
Next, I found some neat add-ins for Visual Studio 2008. The first is the &lt;a href="http://visualstudiogallery.msdn.microsoft.com/en-us/bea9ed59-8857-4032-9666-9af1c1a33969" target=_blank&gt;Source
Code Power Toy&lt;/a&gt;. It outlines your code in a treeview, which makes navigating your
code, especially in complex classes, very easy. Best of all, it's free! It's available
for VS2005 as well.
&lt;/p&gt;
&lt;p&gt;
I also installed the &lt;a href="http://code.msdn.microsoft.com/PowerCommands" target=_blank&gt;Power
Commands&lt;/a&gt; for the VS 2008 IDE. It has some useful right-click functionality, such
as opening a command prompt, and opening the containing folder, and that's just a
small glimpse of what it can do.&amp;nbsp;It seems to be well documented, and I look forward
to exploring all it's functionality. And best thing, this one is free too.
&lt;/p&gt;
&lt;p&gt;
I'll probably post some useful CodeSmith templates I created. I love &lt;a href="http://www.codesmithtools.com/" target=_blank&gt;CodeSmith&lt;/a&gt;,
but sometimes it's tough to find out exactly how to do things, so I will spare the
world the trial-and-error where I can. In the current project I am working on, our
team saved 1,100+ hours, and over $50,000 dollars last month alone by generating nHibernate
code from the templates we created. Yeah, I earned my rate last month for sure. :)
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=c0cbc280-544f-45b1-943c-3715fb32920c" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,c0cbc280-544f-45b1-943c-3715fb32920c.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=de920c29-c8b9-40e4-bb75-cb7daa2af822</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,de920c29-c8b9-40e4-bb75-cb7daa2af822.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,de920c29-c8b9-40e4-bb75-cb7daa2af822.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=de920c29-c8b9-40e4-bb75-cb7daa2af822</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Tonight I didn't get as much time to work on the site as I would have liked, so I
focused on getting the admin pages up on the production server so I could do some
"behind-the-scenes" work remotely. This required some security, which I started last
night, but the data migration for that was a bit more daunting, so I needed to finish
it tonight. While the authentication providers and controls do handle a LOT, it has
an interesting learning-curve, and deployment can be a challenge as well. All-in-all,
it sure beats writing all that code by myself. 
</p>
        <p>
I tried to use a lot of caching and cached settings to help improve the performance
on certain pages, especially my client list. On my admin pages, I made sure to create
a means to reset that cache without having to do a complete server reset. Actually,
the same approach I took would work well for high availability sites, as the method
I used to complete this would not require a server reset to re-load systems. When
I was int he banking industry, high-availability was a huge issue, and simple config
changes meant waiting for a scheduled system outage or worse, an emergency outage.
When I redesigned that site, that was one of the top priorities I had.
</p>
        <p>
It occurred to me how much time it takes to set up the infrastructure of a site: master
pages, common libraries, configuration files, CSS, etc. Once those are done, if done
properly, the rest of the site should go fast. One thing I have found to speed that
up was the use of Visual Studio Project Templates. Combined with code generation like
CodeSmith, you can really generate web sites extremely fast, and get on to coding
the "fun" items. I will write about both of those in the future (CodeSmith and Project
Templates) once the site is stabilized.
</p>
        <p>
Tomorrow night may not have a lot of development, as my parents will be in town. Later
this week, I will be coding my next control: the activity feed. When posts and feeds
are made or read, this control will snag it, and place a brief "teaser" on the home
page.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=de920c29-c8b9-40e4-bb75-cb7daa2af822" />
      </body>
      <title>As we march across the Rubicon, we have Admin pages!</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,de920c29-c8b9-40e4-bb75-cb7daa2af822.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/11/AsWeMarchAcrossTheRubiconWeHaveAdminPages.aspx</link>
      <pubDate>Tue, 11 Aug 2009 05:05:59 GMT</pubDate>
      <description>&lt;p&gt;
Tonight I didn't get as much time to work on the site as I would have liked, so I
focused on getting the admin pages up on the production server so I could do some
"behind-the-scenes" work remotely. This required some security, which I started last
night, but the data migration for that was a bit more daunting, so I needed to finish
it tonight. While the authentication providers and controls do handle a LOT, it has
an interesting learning-curve, and deployment can be a challenge as well. All-in-all,
it sure beats writing all that code by myself. 
&lt;/p&gt;
&lt;p&gt;
I tried to use a lot of caching and cached settings to help improve the performance
on certain pages, especially my client list. On my admin pages, I made sure to create
a means to reset that cache without having to do a complete server reset. Actually,
the same approach I took would work well for high availability sites, as the method
I used to complete this would not require a server reset to re-load systems. When
I was int he banking industry, high-availability was a huge issue, and simple config
changes meant waiting for a scheduled system outage or worse, an emergency outage.
When I redesigned that site, that was one of the top priorities I had.
&lt;/p&gt;
&lt;p&gt;
It occurred to me how much time it takes to set up the infrastructure of a site: master
pages, common libraries, configuration files, CSS, etc. Once those are done, if done
properly, the rest of the site should go fast. One thing I have found to speed that
up was the use of Visual Studio Project Templates. Combined with code generation like
CodeSmith, you can really generate web sites extremely fast, and get on to coding
the "fun" items. I will write about both of those in the future (CodeSmith and Project
Templates) once the site is stabilized.
&lt;/p&gt;
&lt;p&gt;
Tomorrow night may not have a lot of development, as my parents will be in town. Later
this week, I will be coding my next control: the activity feed. When posts and feeds
are made or read, this control will snag it, and place a brief "teaser" on the home
page.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=de920c29-c8b9-40e4-bb75-cb7daa2af822" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,de920c29-c8b9-40e4-bb75-cb7daa2af822.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=031d112b-9b09-493a-bf48-8f168ce1018c</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,031d112b-9b09-493a-bf48-8f168ce1018c.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,031d112b-9b09-493a-bf48-8f168ce1018c.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=031d112b-9b09-493a-bf48-8f168ce1018c</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I finally managed to get my client list online today. From a technological standpoint,
it was pretty straight forward. I store the information in the database, and use my
CodeSmith templates to create a class for extracting the data, and then use a Repeater
to present the information in a table format. I still need to make some changes to
it, but all in all, it works well. Since the data won't be changing often, I did cache
the data to make it come back faster. 
</p>
        <p>
I started working on security for my Administration pages. I need to get that set
up before I can activate the admin pages, but I have run into some issues getting
it all configured. I ran into this once before with the ASP.Net forms authentication
security provider, but this time is a little different, as I only want to secure one
folder. Certainly not too difficult to do, but not as easy as I would have hoped either.
</p>
        <p>
Once I get the security and login page worked out, I'll begin working on my "links"
page. The idea here is that when I blog, or post to twitter, or a few other ideas
I have, it will update the dark blue control on the home page with a summary and hopefully
someone will click through to get the rest of the details. This should be fairly straightforward
to do. Since most of the services respond in XML, I'll just use a factory method to
instantiate the proper object, which will know exactly what information I want to
extract from the XML feed. As I add more items I want to track, I will simply have
to implement the same interface and it will plug right in to my "updater". For the
items which return XML (e.g. RSS or Twitter), I will use LINQ for XML to grab just
want I want and populate the data right into my classes.
</p>
        <p>
Which brings up a point...
</p>
        <p>
I could probably do this almost as easy with XPath. When does it make sense to move
to the more "sexier" technology as opposed something proven and works well? For example,
a lot of times, when a new technology is rolled out, it tends to be buggy and some
of them historically have not performed well (e.g. early XML for those who have been
around a while). All things equal, when does it make sense? Just a rhetorical question,
but one I got hit with recently.
</p>
        <p>
I was in a technical interview for a job I wasn't planning on taking (drive was too
far -- the company I was representing knew this as well, they just wanted me to be
on their radar for the future). I was asked about a particular implementation of the
new List object. Honestly, I know how to use the List object, and he was asking about
some of the internals I really hadn't needed to know. 
</p>
        <p>
If I was having performance issues, I would want to know, and then I would look into
it further. In this case, I was able to provide at least 4 other reasonable implementations
based on the criteria I was given, yet, I still couldn't get the "sexy" answer he
was looking for. At what point does it really matter? For my part, I didn't like NOT
knowing, and I did look it up when I left, but in the big picture, when does it become
relevant? In my book, the practical solution to a relevant problem always supercedes
technical "sexiness". 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=031d112b-9b09-493a-bf48-8f168ce1018c" />
      </body>
      <title>More progress on my site -- Client List!</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,031d112b-9b09-493a-bf48-8f168ce1018c.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/10/MoreProgressOnMySiteClientList.aspx</link>
      <pubDate>Mon, 10 Aug 2009 04:58:40 GMT</pubDate>
      <description>&lt;p&gt;
I finally managed to get my client list online today. From a technological standpoint,
it was pretty straight forward. I store the information in the database, and use my
CodeSmith templates to create a class for extracting the data, and then use a Repeater
to present the information in a table format. I still need to make some changes to
it, but all in all, it works well. Since the data won't be changing often, I did cache
the data to make it come back faster. 
&lt;/p&gt;
&lt;p&gt;
I started working on security for my Administration pages. I need to get that set
up before I can activate the admin pages, but I have run into some issues getting
it all configured. I ran into this once before with the ASP.Net forms authentication
security provider, but this time is a little different, as I only want to secure one
folder. Certainly not too difficult to do, but not as easy as I would have hoped either.
&lt;/p&gt;
&lt;p&gt;
Once I get the security and login page worked out, I'll begin working on my "links"
page. The idea here is that when I blog, or post to twitter, or a few other ideas
I have, it will update the dark blue control on the home page with a summary and hopefully
someone will click through to get the rest of the details. This should be fairly straightforward
to do. Since most of the services respond in XML, I'll just use a factory method to
instantiate the proper object, which will know exactly what information I want to
extract from the XML feed. As I add more items I want to track, I will simply have
to implement the same interface and it will plug right in to my "updater". For the
items which return XML (e.g. RSS or Twitter), I will use LINQ for XML to grab just
want I want and populate the data right into my classes.
&lt;/p&gt;
&lt;p&gt;
Which brings up a point...
&lt;/p&gt;
&lt;p&gt;
I could probably do this almost as easy with XPath. When does it make sense to move
to the more "sexier" technology as opposed something proven and works well? For example,
a lot of times, when a new technology is rolled out, it tends to be buggy and some
of them historically have not performed well (e.g. early XML for those who have been
around a while). All things equal, when does it make sense? Just a rhetorical question,
but one I got hit with recently.
&lt;/p&gt;
&lt;p&gt;
I was in a technical interview for a job I wasn't planning on taking (drive was too
far -- the company I was representing knew this as well, they just wanted me to be
on their radar for the future). I was asked about a particular implementation of the
new List object. Honestly, I know how to use the List object, and he was asking about
some of the internals I really hadn't needed to know. 
&lt;/p&gt;
&lt;p&gt;
If I was having performance issues, I would want to know, and then I would look into
it further. In this case, I was able to provide at least 4 other reasonable implementations
based on the criteria I was given, yet, I still couldn't get the "sexy" answer he
was looking for. At what point does it really matter? For my part, I didn't like NOT
knowing, and I did look it up when I left, but in the big picture, when does it become
relevant? In my book, the practical solution to a relevant problem always supercedes
technical "sexiness". 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=031d112b-9b09-493a-bf48-8f168ce1018c" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,031d112b-9b09-493a-bf48-8f168ce1018c.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=71a6f346-d8d1-4b6d-ba7e-731960fe2e46</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,71a6f346-d8d1-4b6d-ba7e-731960fe2e46.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,71a6f346-d8d1-4b6d-ba7e-731960fe2e46.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=71a6f346-d8d1-4b6d-ba7e-731960fe2e46</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I finally got around to updating my resume, and I pasted it temporarily on my
home page at <a href="http://www.rubiconcomputing.com/" target="_blank">Rubicon Computing
Solutions</a>. That's my company, and it's been a great run of 13 years.  I say
temporarily simply because it will better positioned later, but I realized I really
should have it on there so it gets picked up by some search engines, recruiters and
in general people looking for .Net development in the Phoenix area.
</p>
        <p>
I am in some talks with some other very senior developers I have had the pleasure
of working with over the past couple of years about banding our talent together. I've
tried that before, but these developers have been on their own for a long time, so
we have a very similar background and strong work ethic to build upon. I have always
struggled in the past with partnering up with other developers, as I have very high
expectations of any project I work on. In fact, this is why I have had trouble hiring
help, as my standards of quality aren't met by most developers without substantial
coaching. These developers already have that skill, along with maturity and experience,
which makes this a very exciting opportunity. Interesting how this economy drags some
people down, yet others, like myself see it as an opportunity.
</p>
        <p>
One of the limiting factors I have always had was that I was limited on the size of
projects I could take alone. This changes that dynamic dramatically.
</p>
        <p>
So if you're looking for some quality application development (web or windows), I
specialize in quality service and coding in a Microsoft environment. I can work alone,
with a team, or build and lead teams. You can find more details about those skills <a href="http://www.rubiconcomputing.com/resume/resume.html" target="_blank">here</a>.
Thanks!
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=71a6f346-d8d1-4b6d-ba7e-731960fe2e46" />
      </body>
      <title>A not-so-shameless plug</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,71a6f346-d8d1-4b6d-ba7e-731960fe2e46.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/07/ANotsoshamelessPlug.aspx</link>
      <pubDate>Fri, 07 Aug 2009 05:02:11 GMT</pubDate>
      <description>&lt;p&gt;
I finally got around&amp;nbsp;to updating my resume, and I pasted it temporarily on my
home page at &lt;a href="http://www.rubiconcomputing.com/" target=_blank&gt;Rubicon Computing
Solutions&lt;/a&gt;. That's my company, and it's been a great run of 13 years.&amp;nbsp; I say
temporarily simply because it will better positioned later, but I realized I really
should have it on there so it gets picked up by some search engines, recruiters and
in general people looking for .Net development in the Phoenix area.
&lt;/p&gt;
&lt;p&gt;
I am in some talks with some other very senior developers I have had the pleasure
of working with over the past couple of years about banding our talent together. I've
tried that before, but these developers have been on their own for a long time, so
we have a very similar background and strong work ethic to build upon. I have always
struggled in the past with partnering up with other developers, as I have very high
expectations of any project I work on. In fact, this is why I have had trouble hiring
help, as my standards of quality aren't met by most developers without substantial
coaching. These developers already have that skill, along with maturity and experience,
which makes this a very exciting opportunity. Interesting how this economy drags some
people down, yet others, like myself see it as an opportunity.
&lt;/p&gt;
&lt;p&gt;
One of the limiting factors I have always had was that I was limited on the size of
projects I could take alone. This changes that dynamic dramatically.
&lt;/p&gt;
&lt;p&gt;
So if you're looking for some quality application development (web or windows), I
specialize in quality service and coding in a Microsoft environment. I can work alone,
with a team, or build and lead teams. You can find more details about those skills &lt;a href="http://www.rubiconcomputing.com/resume/resume.html" target=_blank&gt;here&lt;/a&gt;.
Thanks!
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=71a6f346-d8d1-4b6d-ba7e-731960fe2e46" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,71a6f346-d8d1-4b6d-ba7e-731960fe2e46.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Web Services</category>
      <category>Windows</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=93b87350-9e5d-45df-b06e-3ac75edeb809</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,93b87350-9e5d-45df-b06e-3ac75edeb809.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,93b87350-9e5d-45df-b06e-3ac75edeb809.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=93b87350-9e5d-45df-b06e-3ac75edeb809</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Tonight's coding session went by WAY too fast. I integrated <a href="http://devblog.yedda.com/index.php/twitter-c-library/" target="_blank">Yedda's
Twitter API</a> into my admin pages so I could post directly without having to use
another client or browse to Twitter to do it. The next step will be to read my blog
feed and Tweet automatically about the topic. That's for another night though, as
tomorrow night is poker night, and yes, I still play. :)
</p>
        <p>
One change I made to the Yedda library (ok, two.. I ran into an issue with an error
code 471 being returned, but a quick Google search fixed that (sometimes I how effeciently
we coded before Google). I wanted to use LINQ to XML to parse out my response code.
So Instead of returning the XML Document, I convert it to an XDocument using the Parse
method, and return that, like this:
</p>
        <font color="#0000ff" size="2">
          <font color="#0000ff" size="2">
            <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">         public</span>
                <span style="COLOR: #2b91af">XDocument</span> UpdateAsXML(<span style="COLOR: blue">string</span> userName, <span style="COLOR: blue">string</span> password, <span style="COLOR: blue">string</span> text)
</p>
              <p style="MARGIN: 0px">
        {
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">string</span> output
= Update(userName, password, text, <span style="COLOR: #2b91af">OutputFormatType</span>.XML);
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">if</span> (!<span style="COLOR: blue">string</span>.IsNullOrEmpty(output))
</p>
              <p style="MARGIN: 0px">
            {
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: #2b91af">XDocument</span> xmlDocument
= <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">XDocument</span>();
</p>
              <p style="MARGIN: 0px">
                xmlDocument
= <span style="COLOR: #2b91af">XDocument</span>.Parse(output);
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
                <span style="COLOR: blue">return</span> xmlDocument;
</p>
              <p style="MARGIN: 0px">
            }
</p>
              <p style="MARGIN: 0px">
 
</p>
              <p style="MARGIN: 0px">
            <span style="COLOR: blue">return</span><span style="COLOR: blue">null</span>;
</p>
              <p style="MARGIN: 0px">
        }
</p>
            </div>
            <!--EndFragment-->
          </font>
        </font>
        <font size="2">
          <p>
Next, if I want to grab the status from of the post to Twitter, I can use LINQ as
follows (in this case, I want the id so I can see if it was successful):
</p>
          <div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New">
            <p style="MARGIN: 0px">
              <span style="COLOR: #2b91af">TwitterAPI</span> twit = <span style="COLOR: blue">new</span><span style="COLOR: #2b91af">TwitterAPI</span>();
</p>
            <p style="MARGIN: 0px">
                    <span style="COLOR: #2b91af">XDocument</span> doc
= twit.UpdateAsXML(<span style="COLOR: #2b91af">Settings</span>.TwitterUserName(), <span style="COLOR: #2b91af">Settings</span>.TwitterPassword(),
txtPost.Text);
</p>
            <p style="MARGIN: 0px">
 
</p>
            <p style="MARGIN: 0px">
                    <span style="COLOR: blue">var</span> status
= <span style="COLOR: blue">from</span> s <span style="COLOR: blue">in</span> doc.Descendants(<span style="COLOR: #a31515">"status"</span>)
</p>
            <p style="MARGIN: 0px">
                   
             <span style="COLOR: blue">select</span> (<span style="COLOR: blue">string</span>)s.Element(<span style="COLOR: #a31515">"id"</span>);
</p>
            <p style="MARGIN: 0px">
 
</p>
            <p style="MARGIN: 0px">
                    <span style="COLOR: blue">bool</span> found
= <span style="COLOR: blue">false</span>;
</p>
            <p style="MARGIN: 0px">
                    <span style="COLOR: blue">foreach</span> (<span style="COLOR: blue">string</span> id <span style="COLOR: blue">in</span> status)
</p>
            <p style="MARGIN: 0px">
                   
    found = <span style="COLOR: blue">true</span>;
</p>
          </div>
          <!--EndFragment-->
          <p>
I am sure there is a better way to determine if it was successful, but this will work
for now, as there are other things I want to do with the response as well. Since this
worked so well, I plan on converting all the XML calls to XDocuments so I can use
LINQ to work with the response.
</p>
          <p>
That's it for today!
</p>
        </font>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=93b87350-9e5d-45df-b06e-3ac75edeb809" />
      </body>
      <title>Yedda library, Twitter Responses and LINQ to XML</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,93b87350-9e5d-45df-b06e-3ac75edeb809.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/05/YeddaLibraryTwitterResponsesAndLINQToXML.aspx</link>
      <pubDate>Wed, 05 Aug 2009 05:34:05 GMT</pubDate>
      <description>&lt;p&gt;
Tonight's coding session went by WAY too fast. I integrated &lt;a href="http://devblog.yedda.com/index.php/twitter-c-library/" target=_blank&gt;Yedda's
Twitter API&lt;/a&gt; into my admin pages so I could post directly without having to use
another client or browse to Twitter to do it. The next step will be to read my blog
feed and Tweet automatically about the topic. That's for another night though, as
tomorrow night is poker night, and yes, I still play. :)
&lt;/p&gt;
&lt;p&gt;
One change I made to the Yedda library (ok, two.. I ran into an issue with an error
code 471 being returned, but a quick Google search fixed that (sometimes I how effeciently
we coded before Google). I wanted to use LINQ to XML to parse out my response code.
So Instead of returning the XML Document, I convert it to an XDocument using the Parse
method, and return that, like this:
&lt;/p&gt;
&lt;font color=#0000ff size=2&gt;&lt;font color=#0000ff size=2&gt; 
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;public&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt; UpdateAsXML(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; userName, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; password, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; text)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; output
= Update(userName, password, text, &lt;span style="COLOR: #2b91af"&gt;OutputFormatType&lt;/span&gt;.XML);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (!&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;.IsNullOrEmpty(output))
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt; xmlDocument
= &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; xmlDocument
= &lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt;.Parse(output);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; xmlDocument;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;null&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;&lt;/font&gt;&lt;/font&gt;&lt;font size=2&gt; 
&lt;p&gt;
Next, if I want to grab the status from of the post to Twitter, I can use LINQ as
follows (in this case, I want the id so I can see if it was successful):
&lt;/p&gt;
&lt;div style="FONT-SIZE: 10pt; BACKGROUND: white; COLOR: black; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: #2b91af"&gt;TwitterAPI&lt;/span&gt; twit = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; &lt;span style="COLOR: #2b91af"&gt;TwitterAPI&lt;/span&gt;();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: #2b91af"&gt;XDocument&lt;/span&gt; doc
= twit.UpdateAsXML(&lt;span style="COLOR: #2b91af"&gt;Settings&lt;/span&gt;.TwitterUserName(), &lt;span style="COLOR: #2b91af"&gt;Settings&lt;/span&gt;.TwitterPassword(),
txtPost.Text);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;var&lt;/span&gt; status
= &lt;span style="COLOR: blue"&gt;from&lt;/span&gt; s &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; doc.Descendants(&lt;span style="COLOR: #a31515"&gt;"status"&lt;/span&gt;)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;select&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;string&lt;/span&gt;)s.Element(&lt;span style="COLOR: #a31515"&gt;"id"&lt;/span&gt;);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; found
= &lt;span style="COLOR: blue"&gt;false&lt;/span&gt;;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; &lt;span style="COLOR: blue"&gt;foreach&lt;/span&gt; (&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; id &lt;span style="COLOR: blue"&gt;in&lt;/span&gt; status)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&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; found = &lt;span style="COLOR: blue"&gt;true&lt;/span&gt;;
&lt;/p&gt;
&lt;/div&gt;
&lt;!--EndFragment--&gt;
&lt;p&gt;
I am sure there is a better way to determine if it was successful, but this will work
for now, as there are other things I want to do with the response as well. Since this
worked so well, I plan on converting all the XML calls to XDocuments so I can use
LINQ to work with the response.
&lt;/p&gt;
&lt;p&gt;
That's it for today!
&lt;/p&gt;
&lt;/font&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=93b87350-9e5d-45df-b06e-3ac75edeb809" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,93b87350-9e5d-45df-b06e-3ac75edeb809.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=8e641840-54a8-4e88-ada1-e98f308e611f</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,8e641840-54a8-4e88-ada1-e98f308e611f.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,8e641840-54a8-4e88-ada1-e98f308e611f.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=8e641840-54a8-4e88-ada1-e98f308e611f</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
As the main site is developed, I'll detail what decisions I used to create the
site, then a high level overview of how I designed it. Just a warning though, some
of the decisions will seem very arbitrary, as they were. I made them simply because
working on your own site gives you a luxury of trying things you normally can't do
with a client. In my case, a lot of my decisions will be over-engineered, because
I may want to re-use them later.
</p>
        <p>
Of course, the first thing I had to come up with was an overall site layout. I won't
go into that here, as one thing I will never profess to be is a layout guru. I got
a decent design, and I set them up as a master page so the rest of the site development
will go easy. I used VS2008 and C#, and began implementing AJAX where it made sense.
For example, there's a control which updates the current time every 30 seconds or
so, so I could use the update panel and timer control.
</p>
        <p>
The first real functionality I wanted to add was a link to this blog. So I created
a user control, and placed it on the front page. However, I do plan on posting a lot
more here, so I knew it wouldn't be feasible to show every post, so I decided to limit
it to the latest three posts. I wanted to display the title, the date and the first
bit of the post to hopefully catch a reader's attention.
</p>
        <p>
But reading from a feed from sites at two different hosting providers can be tricky.
Not from a security standpoint, as RSS feeds are open, but more from a performance
standpoint. Anyone coming to my portal site should be able to see the latest posts,
and quickly. The fastest way of doing this would be to create a Windows service which
periodically reads the feed, and stores the information in a database. However, I
am not sure I would be able to install a Windows service on my service provider's
server. So......
</p>
        <p>
What<em>  </em>I <em>can</em> do however is read the feed, and place it in cache.
Periodically, I can expire the cache and re-load it, and unless you are the unlucky
soul to have to wait while it loads, the majority of the users will have a quick response.
For that poor soul who waits while cache is refreshed, I used Ajax and the UpdateProgress
control to provide some visual feedback that the page is doing something.
</p>
        <p>
The rest was pretty straightforward. I either request the XML from the RSS feed (or
cache), and use XSLT to display it. It's been a while since I have used XSLT, but
there is a lot of potential there, I expect I will be using a lot more of it in future
controls. I created the class generically so that I could pull any RSS feed
I wanted from it as well.
</p>
        <p>
One great use I found for XSLT was on a high-availability web site which sent a lot
of emails. We wanted to be able to change the email format frequently without bringing
the site down. Using XSLT, we could change the email template files any time to create
very nice HTML based email messages. I read a great article recently about calling
C# functions in your XSLT templates using extension methods, which I plan to use extensively,
as C# is my main domain. Maybe I will use them... I say that as I really would like
to improve my XSLT skills, as I think the technology is highy underused in the .Net
world.
</p>
        <p>
So now I am playing with Twitter feeds and getting the rest of the site content set
up. I also used the AJAX popup control to help prevent any 404 errors as I complete
the functionality. If you've been putting off using the AJAX Control Toolkit for some
reason.. STOP! The amount of functionality these controls offer is amazing, and you
can't beat the price.
</p>
        <p>
That's it for now! If you want more details on how I accomplished this or some sample
code, just send me a comment. Upcoming posts will address the development of the rest
of the site, along with some major wins recently using CodeSmith.
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=8e641840-54a8-4e88-ada1-e98f308e611f" />
      </body>
      <title>First Control -- RSS Feed</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,8e641840-54a8-4e88-ada1-e98f308e611f.aspx</guid>
      <link>http://www.dotnettechnologies.com/2009/08/02/FirstControlRSSFeed.aspx</link>
      <pubDate>Sun, 02 Aug 2009 14:54:16 GMT</pubDate>
      <description>&lt;p&gt;
As the main site is developed, I'll detail what&amp;nbsp;decisions I used to create the
site, then a high level overview of how I designed it. Just a warning though, some
of the decisions will seem very arbitrary, as they were. I made them simply because
working on your own site gives you a luxury of trying things you normally can't do
with a client. In my case, a lot of my decisions will be over-engineered, because
I may want to re-use them later.
&lt;/p&gt;
&lt;p&gt;
Of course, the first thing I had to come up with was an overall site layout. I won't
go into that here, as one thing I will never profess to be is a layout guru. I got
a decent design, and I set them up as a master page so the rest of the site development
will go easy. I used VS2008 and C#, and began implementing AJAX where it made sense.
For example, there's a control which updates the current time every 30 seconds or
so, so I could use the update panel and timer control.
&lt;/p&gt;
&lt;p&gt;
The first real functionality I wanted to add was a link to this blog. So I created
a user control, and placed it on the front page. However, I do plan on posting a lot
more here, so I knew it wouldn't be feasible to show every post, so I decided to limit
it to the latest three posts. I wanted to display the title, the date and the first
bit of the post to hopefully catch a reader's attention.
&lt;/p&gt;
&lt;p&gt;
But reading from a feed from sites at two different hosting providers can be tricky.
Not from a security standpoint, as RSS feeds are open, but more from a performance
standpoint. Anyone coming to my portal site should be able to see the latest posts,
and quickly. The fastest way of doing this would be to create a Windows service which
periodically reads the feed, and stores the information in a database. However, I
am not sure I would be able to install a Windows service on my service provider's
server. So......
&lt;/p&gt;
&lt;p&gt;
What&lt;em&gt;&amp;nbsp; &lt;/em&gt;I &lt;em&gt;can&lt;/em&gt; do however is read the feed, and place it in cache.
Periodically, I can expire the cache and re-load it, and unless you are the unlucky
soul to have to wait while it loads, the majority of the users will have a quick response.
For that poor soul who waits while cache is refreshed, I used Ajax and the UpdateProgress
control to provide some visual feedback that the page is doing something.
&lt;/p&gt;
&lt;p&gt;
The rest was pretty straightforward. I either request the XML from the RSS feed (or
cache), and use XSLT to display it. It's been a while since I have used XSLT, but
there is a lot of potential there, I expect I will be using a lot more of it in future
controls. I created the class&amp;nbsp;generically so&amp;nbsp;that I could pull any RSS feed
I wanted from it as well.
&lt;/p&gt;
&lt;p&gt;
One great use I found for XSLT was on a high-availability web site which sent a lot
of emails. We wanted to be able to change the email format frequently without bringing
the site down. Using XSLT, we could change the email template files any time to create
very nice HTML based email messages. I read a great article recently about calling
C# functions in your XSLT templates using extension methods, which I plan to use extensively,
as C# is my main domain. Maybe I will use them... I say that as I really would like
to improve my XSLT skills, as I think the technology is highy underused in the .Net
world.
&lt;/p&gt;
&lt;p&gt;
So now I am playing with Twitter feeds and getting the rest of the site content set
up. I also used the AJAX popup control to help prevent any 404 errors as I complete
the functionality. If you've been putting off using the AJAX Control Toolkit for some
reason.. STOP! The amount of functionality these controls offer is amazing, and you
can't beat the price.
&lt;/p&gt;
&lt;p&gt;
That's it for now! If you want more details on how I accomplished this or some sample
code, just send me a comment. Upcoming posts will address the development of the rest
of the site, along with some major wins recently using CodeSmith.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=8e641840-54a8-4e88-ada1-e98f308e611f" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,8e641840-54a8-4e88-ada1-e98f308e611f.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>Design</category>
      <category>General</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=e71c0a9e-e77d-4544-8698-d2c8674e7435</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,e71c0a9e-e77d-4544-8698-d2c8674e7435.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,e71c0a9e-e77d-4544-8698-d2c8674e7435.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=e71c0a9e-e77d-4544-8698-d2c8674e7435</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
So it has been hit or miss posting here, but I am trying to correct it by bringing
on some additional help. I set up a new blog, <a href="http://www.developernation.net">developernation.net</a>,
and begun getting some content on there. Likely I'll crosspost on here too (my content
anyways) but likely most new entries are going to be there first. I figured if I could
get someone else on there helping doing some content, it will have more regular posts.
This blog will continue, just a lag a few days on the content of theother site, and
contain more personal observations.
</p>
        <p>
So swing on by and pop in. I've started off with a bang, and I am in the process of
posting a web service design I created and tested which handles paging and sorting
of data on the server, which my initial tests have shown to be highly efficient. I
am walking through the entire design, and by the end of the weekend I hope to have
the series done and the code posted. If not, you can wait a few days and I will post
it all here as well. 
</p>
        <p>
Thanks!
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=e71c0a9e-e77d-4544-8698-d2c8674e7435" />
      </body>
      <title>A change of directions...</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,e71c0a9e-e77d-4544-8698-d2c8674e7435.aspx</guid>
      <link>http://www.dotnettechnologies.com/2006/04/28/AChangeOfDirections.aspx</link>
      <pubDate>Fri, 28 Apr 2006 15:38:06 GMT</pubDate>
      <description>&lt;p&gt;
So it has been hit or miss posting here, but I am trying to correct it by bringing
on some additional help. I set up a new blog, &lt;a href="http://www.developernation.net"&gt;developernation.net&lt;/a&gt;,
and begun getting some content on there. Likely I'll crosspost on here too (my content
anyways) but likely most new entries are going to be there first. I figured if I could
get someone else on there helping doing some content, it will have more regular posts.
This blog will continue, just a lag a few days on the content of theother site, and
contain more personal observations.
&lt;/p&gt;
&lt;p&gt;
So swing on by and pop in. I've started off with a bang, and I am in the process of
posting a web service design I created and tested which handles paging and sorting
of data on the server, which my initial tests have shown to be highly efficient. I
am walking through the entire design, and by the end of the weekend I hope to have
the series done and the code posted. If not, you can wait a few days and I will post
it all here as well. 
&lt;/p&gt;
&lt;p&gt;
Thanks!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=e71c0a9e-e77d-4544-8698-d2c8674e7435" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,e71c0a9e-e77d-4544-8698-d2c8674e7435.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Debugging</category>
      <category>Design</category>
      <category>General</category>
      <category>SQL Tips</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
      <category>VB.Net</category>
      <category>Web Services</category>
      <category>Windows</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=5dafa1e9-5ed0-4f7e-bb5e-bf0aa92b019f</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,5dafa1e9-5ed0-4f7e-bb5e-bf0aa92b019f.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,5dafa1e9-5ed0-4f7e-bb5e-bf0aa92b019f.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5dafa1e9-5ed0-4f7e-bb5e-bf0aa92b019f</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I had a great need again for WinCV today, and was beginning to work out in my mind
how I would rewrite it, as I posted earlier. However, it hit me that <a href="http://www.aisto.com/roeder/dotnet/" target="_blank">Lutz
Roeder's Reflector for .Net</a> might actually do what I needed. It does, it turns
out. I did have to modify the .cfg file to look at the new assemblies for VS2005,
but once I did that, the search functionality worked wonders. So, even though it would
have proven to be a great learning experience, I am going to forego putting a rehash
together, and stick with something that works very nicely..
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=5dafa1e9-5ed0-4f7e-bb5e-bf0aa92b019f" />
      </body>
      <title>Solution to the WinCV issue...</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,5dafa1e9-5ed0-4f7e-bb5e-bf0aa92b019f.aspx</guid>
      <link>http://www.dotnettechnologies.com/2006/03/22/SolutionToTheWinCVIssue.aspx</link>
      <pubDate>Wed, 22 Mar 2006 23:00:20 GMT</pubDate>
      <description>&lt;p&gt;
I had a great need again for WinCV today, and was beginning to work out in my mind
how I would rewrite it, as I posted earlier. However, it hit me that &lt;a href="http://www.aisto.com/roeder/dotnet/" target=_blank&gt;Lutz
Roeder's Reflector for .Net&lt;/a&gt; might actually do what I needed. It does, it turns
out. I did have to modify the .cfg file to look at the new assemblies for VS2005,
but once I did that, the search functionality worked wonders. So, even though it would
have proven to be a great learning experience, I am going to forego putting a rehash
together, and stick with something that works very nicely..
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=5dafa1e9-5ed0-4f7e-bb5e-bf0aa92b019f" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,5dafa1e9-5ed0-4f7e-bb5e-bf0aa92b019f.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>General</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=48b279f9-c7e2-406f-aa87-64856644c179</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,48b279f9-c7e2-406f-aa87-64856644c179.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,48b279f9-c7e2-406f-aa87-64856644c179.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=48b279f9-c7e2-406f-aa87-64856644c179</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I found some details on WinCV for VS2005 (or the lack thereof). As near as I can ascertain,
if you have VS2005 only, and place WinCV on that system it will work for the .Net
2.0 libraries. I don't know how that works as it seems the information is
hardcoded into WinCV.
</p>
        <p>
So, it was such a great utility, and I think it lends itself to some great enhancements,
so I think I am going to write a version which is VS2005+ compliant. Some features
I want to add:
</p>
        <ul>
          <li>
Quick linking to the help topic for a class/method</li>
          <li>
Ability to easily add external assemblies WITHOUT having to use the command line</li>
        </ul>
        <p>
I plan on keeping the same basic interface though, as it was simple and effective.
Not sure how much I willl get to work on this, or how long it will take, but I will
post it here and probably CodeProject when I get it finished.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=48b279f9-c7e2-406f-aa87-64856644c179" />
      </body>
      <title>WinCV v2 revisited</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,48b279f9-c7e2-406f-aa87-64856644c179.aspx</guid>
      <link>http://www.dotnettechnologies.com/2006/03/22/WinCVV2Revisited.aspx</link>
      <pubDate>Wed, 22 Mar 2006 15:44:55 GMT</pubDate>
      <description>&lt;p&gt;
I found some details on WinCV for VS2005 (or the lack thereof). As near as I can ascertain,
if you have VS2005 only, and place WinCV on that system it will work for the .Net
2.0 libraries.&amp;nbsp;I don't know how that works&amp;nbsp;as it seems the information is
hardcoded into WinCV.
&lt;/p&gt;
&lt;p&gt;
So, it was such a great utility, and I think it lends itself to some great enhancements,
so I think I am going to write a version which is VS2005+ compliant. Some features
I want to add:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Quick linking to the help topic for a class/method&lt;/li&gt;
&lt;li&gt;
Ability to easily add external assemblies WITHOUT having to use the command line&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I plan on keeping the same basic interface though, as it was simple and effective.
Not sure how much I willl get to work on this, or how long it will take, but I will
post it here and probably CodeProject when I get it finished.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=48b279f9-c7e2-406f-aa87-64856644c179" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,48b279f9-c7e2-406f-aa87-64856644c179.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>General</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=5876a92e-efe9-4698-ab08-cf57d4ed2112</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,5876a92e-efe9-4698-ab08-cf57d4ed2112.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,5876a92e-efe9-4698-ab08-cf57d4ed2112.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=5876a92e-efe9-4698-ab08-cf57d4ed2112</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
          <font face="Lucida Sans Typewriter" color="#000000">A year ago, I completed my MCSD
for .Net. One of the attractive<br />
benefits of this certification (as well as the MCDBA) was a $500<br />
discount on a one-year MSDN Universal subscription during the first<br />
year of certification.<br /><br />
Although the MCSD benefits page still lists this benefit<br />
(</font>
          <a href="http://www.microsoft.com/learning/mcp/mcsd/benefits.asp" target="_blank">
            <font face="Lucida Sans Typewriter" color="#9136ad">http://www.microsoft.com/learning/mcp/mcsd/benefits.asp</font>
          </a>
          <font face="Lucida Sans Typewriter" color="#000000">),
they<br />
quietly removed it as of April 2005. The text on the page still<br />
states the following:<br />
Rebates or discounts on a one-year subscription to MSDN during the<br />
first year of certification.<br /><br />
If you call or write to get the certificate as I did, you'll get the<br />
terse response it's no longer available, and they just haven't<br />
updated the site. I figured I would help them get the word out since<br />
they didn't deem it important enough to change on their site or<br />
announce. It would be a shame if anyone expected this benefit based<br />
on the MS web site information.</font>
        </p>
        <p>
-------------------------------------------------------------------------
</p>
        <p>
Above is what I posted to our local .Net community group on Yahoo. Now I am going
to add some personal comments. Once again, MS has dropped the ball in supporting the
developer community. Earlier this year, MS announced the MSDN Universal would not
include the new .Net Team Development system (or some name like that -- I am too lazy
to go look it up). Fortunately, enough of an uproar went out that they reversed that
decision. Their waning support of VB also caused a petition/uproar. Likely, since
the MCSD/MCDBA community is a lot smaller, there isn't likely to be a huge outcry
on this issue.
</p>
        <p>
This is a HUGE mistake on MS's behalf. Someone that is likely to spend the extra time
and money to get certifications are the ones MS should really cater to. There's always
been a criticism that the certifications are worthless, and that benefit alone
made it real easy to justify spending the money on books, training materials and exam
costs for achieving the certification. I won't argue the merits of the certifications
here, but I have a lot of them -- MCP, MCDBA, MCSD for VB, MCSD for .Net (C#), and
MCAD. Will I continue? I may have to given I am an Independent Contractor and it helps
to get me in the door. Will I recommend it to someone not in my position? Not likely.
</p>
        <p>
Don't get me wrong, the MSDN Universal is still a great deal. My disgust over this
situation is that the benefit is <strong>still</strong> listed, as well as no announcement
in April 2005 when they made this decision (or if they did, I sure didn't see it).
I have been one of the most stalwart supporters of Microsoft over the years,
and I have personally been involved in projects which have generated millions in
licensing revenues for Microsoft in the last 10 years. The past 1.5 years I have watched
MS anger the core base of developers.
</p>
        <p>
I think this is indicative of the internal problems at MS, and why Google is going
to be a viable competitor to MS. In a paraphrase of the words of Stephen King, and
the Dark Tower series, MS has forgotten the face of their father. One of the reasons
MS dominated the market over Apple was that MS supported developers way beyond the
norm. In the name of profit, I think we are seeing this slowly change.<br /></p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=5876a92e-efe9-4698-ab08-cf57d4ed2112" />
      </body>
      <title>MSDN Universal Discount for MCSD/MCDBA </title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,5876a92e-efe9-4698-ab08-cf57d4ed2112.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/10/07/MSDNUniversalDiscountForMCSDMCDBA.aspx</link>
      <pubDate>Fri, 07 Oct 2005 15:57:27 GMT</pubDate>
      <description>&lt;p&gt;
&lt;font face="Lucida Sans Typewriter" color=#000000&gt;A year ago, I completed my MCSD
for .Net. One of the attractive&lt;br&gt;
benefits of this certification (as well as the MCDBA) was a $500&lt;br&gt;
discount on a one-year MSDN Universal subscription during the first&lt;br&gt;
year of certification.&lt;br&gt;
&lt;br&gt;
Although the MCSD benefits page still lists this benefit&lt;br&gt;
(&lt;/font&gt;&lt;a href="http://www.microsoft.com/learning/mcp/mcsd/benefits.asp" target=_blank&gt;&lt;font face="Lucida Sans Typewriter" color=#9136ad&gt;http://www.microsoft.com/learning/mcp/mcsd/benefits.asp&lt;/font&gt;&lt;/a&gt;&lt;font face="Lucida Sans Typewriter" color=#000000&gt;),
they&lt;br&gt;
quietly removed it as of April 2005. The text on the page still&lt;br&gt;
states the following:&lt;br&gt;
Rebates or discounts on a one-year subscription to MSDN during the&lt;br&gt;
first year of certification.&lt;br&gt;
&lt;br&gt;
If you call or write to get the certificate as I did, you'll get the&lt;br&gt;
terse response it's no longer available, and they just haven't&lt;br&gt;
updated the site. I figured I would help them get the word out since&lt;br&gt;
they didn't deem it important enough to change on their site or&lt;br&gt;
announce. It would be a shame if anyone expected this benefit based&lt;br&gt;
on the MS web site information.&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
-------------------------------------------------------------------------
&lt;/p&gt;
&lt;p&gt;
Above is what I posted to our local .Net community group on Yahoo. Now I am going
to add some personal comments. Once again, MS has dropped the ball in supporting the
developer community. Earlier this year, MS announced the MSDN Universal would not
include the new .Net Team Development system (or some name like that -- I am too lazy
to go look it up). Fortunately, enough of an uproar went out that they reversed that
decision. Their waning support of VB also caused a petition/uproar. Likely, since
the MCSD/MCDBA&amp;nbsp;community is a lot smaller, there isn't likely to be a huge outcry
on this issue.
&lt;/p&gt;
&lt;p&gt;
This is a HUGE mistake on MS's behalf. Someone that is likely to spend the extra time
and money to get certifications are the ones MS should really cater to. There's always
been a criticism that the certifications are worthless, and that benefit&amp;nbsp;alone
made it real easy to justify spending the money on books, training materials and exam
costs for achieving the certification. I won't argue the merits of the certifications
here, but I have a lot of them -- MCP, MCDBA, MCSD for VB, MCSD for .Net (C#), and
MCAD. Will I continue? I may have to given I am an Independent Contractor and it helps
to get me in the door. Will I recommend it to someone not in my position? Not likely.
&lt;/p&gt;
&lt;p&gt;
Don't get me wrong, the MSDN Universal is still a great deal. My disgust over this
situation is that the benefit is &lt;strong&gt;still&lt;/strong&gt; listed, as well as no announcement
in April 2005 when they made this decision (or if they did, I sure didn't see it).
I have&amp;nbsp;been one of the most stalwart supporters of Microsoft over the years,
and I have personally been involved in projects which have generated millions&amp;nbsp;in
licensing revenues for Microsoft in the last 10 years. The past 1.5 years I have watched
MS anger the core base of developers.
&lt;/p&gt;
&lt;p&gt;
I think this is indicative of the internal problems at MS, and why Google is going
to be a viable competitor to MS. In a paraphrase of the words of Stephen King, and
the Dark Tower series, MS has forgotten the face of their father. One of the reasons
MS dominated the market over Apple was that MS supported developers way beyond the
norm. In the name of profit, I think we are seeing this slowly change.&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=5876a92e-efe9-4698-ab08-cf57d4ed2112" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,5876a92e-efe9-4698-ab08-cf57d4ed2112.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
      <category>VB.Net</category>
      <category>Windows</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=42aee519-178f-4c39-a2d0-0318ad74be2b</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,42aee519-178f-4c39-a2d0-0318ad74be2b.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,42aee519-178f-4c39-a2d0-0318ad74be2b.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=42aee519-178f-4c39-a2d0-0318ad74be2b</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Once again I have disappeared from blogging. Let's face it, I rarely get to do it.
I also need to upgrade this DasBlog but I have been so busy I haven't been able to
do that, even though someone kindly wrote me and told me it would solve my spam comment
problem. Maybe this weekend...
</p>
        <p>
But I wanted to blog because I found a weird problem, with a weirder solution. I wrote
a Windows service in C# which periodically loads some data, based on the time since
the last load. So dates are a bit important in this process.
</p>
        <p>
First, the cryptic message: “<font color="#191970">Internal Query Processor
Error: The query processor could not produce a query plan. Contact your primary support
provider for more information</font>”.  A Google search turned up several
solutions, but most of them relied on a service patch. What's wierder is that the
error was intermittant. The procs would run fine in Query Analyzer, but not from
C#.
</p>
        <p>
Finally, I tried the unlikely. Instead of passing in my parameters as  DateTime
values, I passed them in as SqlDbType.Varchar, and in the proc made sure and converted
them to DateTime values. Lo and behold, the problem went away.....Go figure!
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=42aee519-178f-4c39-a2d0-0318ad74be2b" />
      </body>
      <title>Bizarre error, bizarre solution...</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,42aee519-178f-4c39-a2d0-0318ad74be2b.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/09/20/BizarreErrorBizarreSolution.aspx</link>
      <pubDate>Tue, 20 Sep 2005 22:50:34 GMT</pubDate>
      <description>&lt;p&gt;
Once again I have disappeared from blogging. Let's face it, I rarely get to do it.
I also need to upgrade this DasBlog but I have been so busy I haven't been able to
do that, even though someone kindly wrote me and told me it would solve my spam comment
problem. Maybe this weekend...
&lt;/p&gt;
&lt;p&gt;
But I wanted to blog because I found a weird problem, with a weirder solution. I wrote
a Windows service in C# which periodically loads some data, based on the time since
the last load. So dates are a bit important in this process.
&lt;/p&gt;
&lt;p&gt;
First, the cryptic message: &amp;#8220;&lt;font color=#191970&gt;Internal Query Processor Error:
The query processor could not produce a query plan. Contact your primary support provider
for more information&lt;/font&gt;&amp;#8221;.&amp;nbsp; A Google search turned up several solutions,
but most of them relied on a service patch. What's wierder is that the error was intermittant.&amp;nbsp;The
procs would run fine in Query Analyzer, but not from C#.
&lt;/p&gt;
&lt;p&gt;
Finally, I tried the unlikely. Instead of passing in my parameters as&amp;nbsp;&amp;nbsp;DateTime
values, I passed them in as SqlDbType.Varchar, and in the proc made sure and converted
them to DateTime values. Lo and behold, the problem went away.....Go figure!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=42aee519-178f-4c39-a2d0-0318ad74be2b" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,42aee519-178f-4c39-a2d0-0318ad74be2b.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>General</category>
      <category>SQL Tips</category>
      <category>Tips and Tricks</category>
      <category>VB.Net</category>
      <category>Windows</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=faefbcf2-c211-4893-820b-0aaab66e31be</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,faefbcf2-c211-4893-820b-0aaab66e31be.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,faefbcf2-c211-4893-820b-0aaab66e31be.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=faefbcf2-c211-4893-820b-0aaab66e31be</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Extremes in anything (IMHO) are typically not good. Extreme temperatures, religeons,
attitudes -- you name it, likely there is a downside. In programming, it's no different.
Now, while not a big fan of Extreme Programming, there's a couple of extremes from
it that bother me. One is that you shouldn't include documentation. The other, which
I suspect  was someone's personal preference, was not to use the “Region”
directives in C# (or I guess VB.Net either). Here's a little history...
</p>
        <p>
This guy was a former Java programmer working for a large chip manufacturer. He was
supposed to be a XP guru, so he was transferred to the local site to help a team in
it's transition to the XP methodology. 
</p>
        <p>
Strike 1 -- he knew the methodology well, but he was by no means an expert in the
language of the group. Why was this a strike? I guess technological bias in that his
preferences to his other language directed him to want to make the .Net environment
the same as a java environment. 
</p>
        <p>
Strike 2 -- It was his way or the highway. The environment was such that one or two
developers had 95% of the say on development decisions. Part of the reason for this
is that wacky trend in which everyone is ranked from best to worst in terms of raises,
options and promotion (for more info what I am talking about, read this article, which
is the same process -- <a href="http://www.sqlservercentral.com/newsletter/view_newsletter.asp?dt=5/26/2005" target="_blank">Saying
Goodbye</a>). No one would ever argue with the two for fear of getting a bad ranking
for being considered a troublemaker.
</p>
        <p>
Regardless, I digress, but I do think it's important to understand why sometimes these
extremes come about in an environment. I was a contractor brought on to bring some
quick wins for a project, and it was my first (and likely last) venture into the XP
methodology. They needed code, and they needed it fast. 
</p>
        <p>
One problem I addressed was the lack of uniformity on the project. We had three developers,
which meant three different styles of programming. Even with XP, that meant one of
us was alone, and the other two would spend the pair time arguning over which style
was a standard and best (even though standards existed -- they were just never used
because of informal rules imposed by the 2 'chiefs'). I decided to create a template
which would standardize (and speed up) our development. I organized the code within
the controls into regions, and deployed them onto our machines with anticipation I
easily saved our team15-20 minutes each time we created a new control.
</p>
        <p>
Alas, it was scrapped instantly. Why? Well, it seems in my templates, I placed the
code into logical “regions” -- e.g. Public Properties, Public Methods,
Private Methods, etc. I was “informed” (even though I had been using regions
for a couple of months now) that regions were not allowed, because all they did was
hide bad code. WHAT???!! Well, I liked the contract, and knew the results if I stood
up to them, so I bit my tongue and moved on. It has bothered me ever since, but I
never took the time to formulate an argument as to why regions are actually a good
idea. 
</p>
        <p>
Why bring this up today after a year has passed? Well, I was coding something, and
the constructor was hidden by a region. I was thinking “Hmm, if we just left
the constructors out of regions, it would be easy to read, because the regions would
hide the internal implementations I don't care about, yet at a glance I can see how
to instantiate the object” (hmm, I think they call that encapsulation) and use
it. Now that right there justifies the use of regions alone.... I can actually think
of a lot of reasons to use regions, and I do it religeously where my client has no
opition about it. 
</p>
        <p>
Just a flashback from the past.... anyone got a counter opinion? Regardless, it just
goes to show extreme anything typically isn't a good thing in my mind. You have to
be flexible in your approach to life if you plan on growing...
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=faefbcf2-c211-4893-820b-0aaab66e31be" />
      </body>
      <title>It just occurred to me...why extremes are bad in programming</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,faefbcf2-c211-4893-820b-0aaab66e31be.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/05/27/ItJustOccurredToMewhyExtremesAreBadInProgramming.aspx</link>
      <pubDate>Fri, 27 May 2005 17:28:46 GMT</pubDate>
      <description>&lt;p&gt;
Extremes in anything (IMHO) are typically not good. Extreme temperatures, religeons,
attitudes -- you name it, likely there is a downside. In programming, it's no different.
Now, while not a big fan of Extreme Programming, there's a couple of extremes from
it that bother me. One is that you shouldn't include documentation. The other, which
I suspect&amp;nbsp; was someone's personal preference, was not to use the &amp;#8220;Region&amp;#8221;
directives in C# (or I guess VB.Net either). Here's a little history...
&lt;/p&gt;
&lt;p&gt;
This guy was a former Java programmer working for a large chip manufacturer. He was
supposed to be a XP guru, so he was transferred to the local site to help a team in
it's transition to the XP methodology. 
&lt;/p&gt;
&lt;p&gt;
Strike 1 -- he knew the methodology well, but he was by no means an expert in the
language of the group. Why was this a strike? I guess technological bias in that his
preferences to his other language directed him to want to make the .Net environment
the same as a java environment. 
&lt;/p&gt;
&lt;p&gt;
Strike 2 -- It was his way or the highway. The environment was such that one or two
developers had 95% of the say on development decisions. Part of the reason for this
is that wacky trend in which everyone is ranked from best to worst in terms of raises,
options and promotion (for more info what I am talking about, read this article, which
is the same process -- &lt;a href="http://www.sqlservercentral.com/newsletter/view_newsletter.asp?dt=5/26/2005" target=_blank&gt;Saying
Goodbye&lt;/a&gt;). No one would ever argue with the two for fear of getting a bad ranking
for being considered a troublemaker.
&lt;/p&gt;
&lt;p&gt;
Regardless, I digress, but I do think it's important to understand why sometimes these
extremes come about in an environment. I was a contractor brought on to bring some
quick wins for a project, and it was my first (and likely last) venture into the XP
methodology. They needed code, and they needed it fast. 
&lt;/p&gt;
&lt;p&gt;
One problem I addressed was the lack of uniformity on the project. We had three developers,
which meant three different styles of programming. Even with XP, that meant one of
us was alone, and the other two would spend the pair time arguning over which style
was a standard and best (even though standards existed -- they were just never used
because of informal rules imposed by the 2 'chiefs'). I decided to create a template
which would standardize (and speed up) our development. I organized the code within
the controls into regions, and deployed them onto our machines with anticipation I
easily saved our team15-20 minutes each time we created a new control.
&lt;/p&gt;
&lt;p&gt;
Alas, it was scrapped instantly. Why? Well, it seems in my templates, I placed the
code into logical &amp;#8220;regions&amp;#8221; -- e.g. Public Properties, Public Methods,
Private Methods, etc. I was &amp;#8220;informed&amp;#8221; (even though I had been using regions
for a couple of months now) that regions were not allowed, because all they did was
hide bad code. WHAT???!! Well, I liked the contract, and knew the results if I stood
up to them, so I bit my tongue and moved on. It has bothered me ever since, but I
never took the time to formulate an argument as to why regions are actually a good
idea. 
&lt;/p&gt;
&lt;p&gt;
Why bring this up today after a year has passed? Well, I was coding something, and
the constructor was hidden by a region. I was thinking &amp;#8220;Hmm, if we just left
the constructors out of regions, it would be easy to read, because the regions would
hide the internal implementations I don't care about, yet at a glance I can see how
to instantiate the object&amp;#8221; (hmm, I think they call that encapsulation) and use
it. Now that right there justifies the use of regions alone.... I can actually think
of a lot of reasons to use regions, and I do it religeously where my client has no
opition about it. 
&lt;/p&gt;
&lt;p&gt;
Just a flashback from the past.... anyone got a counter opinion? Regardless, it just
goes to show extreme anything typically isn't a good thing in my mind. You have to
be flexible in your approach to life if you plan on growing...
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=faefbcf2-c211-4893-820b-0aaab66e31be" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,faefbcf2-c211-4893-820b-0aaab66e31be.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>VB.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=d98820c4-cb7c-4348-8d80-b59c6d514d01</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,d98820c4-cb7c-4348-8d80-b59c6d514d01.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,d98820c4-cb7c-4348-8d80-b59c6d514d01.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=d98820c4-cb7c-4348-8d80-b59c6d514d01</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Tentatively, my current project is set to end in October. No big deal there, as I
have had absolutely no bench days in the past 10 years as an Independent Contractor.
In fact, during most of those 10 years I have been working 55-80+ hours per week and
having a great time doing it. I don't do the book thing or magazine article thing
because quite frankly, I don't have time because I am busy doing billable work which
pays a lot more. I havn't needed self-promotion thing either because almost all my
business comes from referrals from current or past customers.
</p>
        <p>
Then along come kids, and dang if you don't suddenly want to spend more time at home
and improve their quality of life (and mine). My current project wants to bring me
on full time, and we've had some preliminary discussions on it, and I am willing to
take the pay cut in my pay for one simple thing: I want to work remotely
and raise my kids in the country. Their attitude is like mine, which is that should
be fine since I have a strong work ethic and can get things done, what does it matter
where I work as long as I have a phone and internet connection. However, there are
data security concerns and management concerns which would need to be overcome. 
</p>
        <p>
I have plenty of time, since barring disaster, the contract won't be over until
October sometime. But I figure I will start self-promoting just in case someone from
a company who doesn't mind remote employees stumbles on this blog. Towards October,
I will go full bore trying to close something out, and in the meantime I plan on blogging
much more so I can display what talents I can bring to the table. 
</p>
        <p>
If any companies out there that come up on this, and want a great employee (C#/VB
developer with lots of SQL Server and architect/designer/coding and full-life cycle
development) that brings a lot of experience, a great professional attitude and
presence as well as the ability to code like the wind (and good code at that..), then
drop me a line and let's talk. 
</p>
        <p>
Here's a <a href="http://www.rubiconcomputing.com/resume/resume.html" target="_blank">resume </a>just
in case.. 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=d98820c4-cb7c-4348-8d80-b59c6d514d01" />
      </body>
      <title>Self Promotion</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,d98820c4-cb7c-4348-8d80-b59c6d514d01.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/05/26/SelfPromotion.aspx</link>
      <pubDate>Thu, 26 May 2005 23:33:35 GMT</pubDate>
      <description>&lt;p&gt;
Tentatively, my current project is set to end in October. No big deal there, as I
have had absolutely no bench days in the past 10 years as an Independent Contractor.
In fact, during most of those 10 years I have been working 55-80+ hours per week and
having a great time doing it. I don't do the book thing or magazine article thing
because quite frankly, I don't have time because I am busy doing billable work which
pays a lot more. I havn't needed self-promotion thing either because almost all my
business comes from referrals from current or past customers.
&lt;/p&gt;
&lt;p&gt;
Then along come kids, and dang if you don't suddenly want to spend more time at home
and improve their quality of life (and mine). My current project wants to bring me
on full time, and we've had some preliminary discussions on it, and I am willing to
take&amp;nbsp;the pay&amp;nbsp;cut in my pay for one simple thing: I want to work remotely
and raise my kids in the country. Their attitude is like mine, which is that should
be fine since I have a strong work ethic and can get things done, what does it matter
where I work as long as I have a phone and internet connection. However, there are
data security concerns and management concerns which would need to be overcome. 
&lt;/p&gt;
&lt;p&gt;
I&amp;nbsp;have plenty of time, since barring disaster, the contract won't be over until
October sometime. But I figure I will start self-promoting just in case someone from
a company who doesn't mind remote employees stumbles on this blog. Towards October,
I will go full bore trying to close something out, and in the meantime I plan on blogging
much more so I can display what talents I can bring to the table. 
&lt;/p&gt;
&lt;p&gt;
If any companies out there that come up on this, and want a great employee (C#/VB
developer with lots of SQL Server and architect/designer/coding and full-life cycle
development)&amp;nbsp;that brings a lot of experience, a great professional attitude and
presence as well as the ability to code like the wind (and good code at that..), then
drop me a line and let's talk. 
&lt;/p&gt;
&lt;p&gt;
Here's a &lt;a href="http://www.rubiconcomputing.com/resume/resume.html" target=_blank&gt;resume &lt;/a&gt;just
in case.. 
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=d98820c4-cb7c-4348-8d80-b59c6d514d01" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,d98820c4-cb7c-4348-8d80-b59c6d514d01.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>SQL Tips</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
      <category>VB.Net</category>
      <category>Windows</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=9371af86-0405-4beb-bd2e-b0b1f0884ae1</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,9371af86-0405-4beb-bd2e-b0b1f0884ae1.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,9371af86-0405-4beb-bd2e-b0b1f0884ae1.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=9371af86-0405-4beb-bd2e-b0b1f0884ae1</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I bought CodeSmith back in v2, but I was so busy I never got a chance to do more than
play around with it. So now v3 is released, and I was looking at the improvements
(like Intellisense) and decided I would take a look at it again. Boy, was I glad I
did..
</p>
        <p>
Don't get me wrong, I wasn't putting it off because I think code generation and templates
are bad. In fact, quite the opposite. When I first started my business, I had a few
people working with me part-time, and then finally full time as the business grew.
What I found was that in the end, I apparently hold my coding standards to a higher
value than others and I would end up coding 90% of the application myself. I realized
quickly there were a few huge advantages to automated code generation. Here's a few:
</p>
        <ul>
          <li>
Fewer errors (as long as you fix the templates as errors are encountered)</li>
          <li>
One developer can do the work of 4-5 once you get a good architecture set up</li>
          <li>
Standards enforcement is a no-brainer when you are all working off the same templates</li>
          <li>
You can spend more time on UI usability and data structure because 90% of the infrastructure
stuff is done automatically</li>
          <li>
Changes are easy. Change the structure and regenerate the code, and you are off again.</li>
        </ul>
        <p>
I could go on and on about it. I had written a series of VB6 addins which I used based
off Rocky Lhotka's BusinessObjects book for VB5. In hours I could generate almost
all of my middle and data tier code. A tweak here and there, and I was doing the fun
stuff like UI coding. 
</p>
        <p>
Along comes .Net, and my addins were irrelevant. I created a couple of quick and dirty
addins, but I was so busy heads-down coding, I didn't have time to create new templates
to reflect the impact of .Net. I did create some common libraries of functions which
got me through a good chunk of redundant coding, so that was going to have to do the
job for the time.  I had always intended on going back and re-coding some new
templates, but it never happened. 
</p>
        <p>
I am currently working on a project and we are horribly understaffed, and there's
no relief in sight. There are some huge deadlines coming up, and it's time to make
the rubber hit the road. I already code fast (and tight), but I needed to clone myself
a couple times over to make the deadlines. So when the announcement came this week
of CodeSmith 3.0, I decided I would take a new serious look at it and see what it
could do for me. 
</p>
        <p>
Holy crap! In a matter of hours I had some pretty solid templates up and running,
which will save the team many, many hours of redundant coding tasks in building this
application. I have so many ideas for new templates it's scary, and I have only
scratched the surface for what the tool can do. If you haven't looked at it yet, I
recommend immediately going to <a href="http://www.codesmithtools.com/" target="_blank">CodeSmith</a> and
downloading a trial.
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=9371af86-0405-4beb-bd2e-b0b1f0884ae1" />
      </body>
      <title>CodeSmith rocks!</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,9371af86-0405-4beb-bd2e-b0b1f0884ae1.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/05/26/CodeSmithRocks.aspx</link>
      <pubDate>Thu, 26 May 2005 23:19:32 GMT</pubDate>
      <description>&lt;p&gt;
I bought CodeSmith back in v2, but I was so busy I never got a chance to do more than
play around with it. So now v3 is released, and I was looking at the improvements
(like Intellisense) and decided I would take a look at it again. Boy, was I glad I
did..
&lt;/p&gt;
&lt;p&gt;
Don't get me wrong, I wasn't putting it off because I think code generation and templates
are bad. In fact, quite the opposite. When I first started my business, I had a few
people working with me part-time, and then finally full time as the business grew.
What I found was that in the end, I apparently hold my coding standards to a higher
value than others and I would end up coding 90% of the application myself. I realized
quickly there were a few huge advantages to automated code generation. Here's a few:
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
Fewer errors (as long as you fix the templates as errors are encountered)&lt;/li&gt;
&lt;li&gt;
One developer can do the work of 4-5 once you get a good architecture set up&lt;/li&gt;
&lt;li&gt;
Standards enforcement is a no-brainer when you are all working off the same templates&lt;/li&gt;
&lt;li&gt;
You can spend more time on UI usability and data structure because 90% of the infrastructure
stuff is done automatically&lt;/li&gt;
&lt;li&gt;
Changes are easy. Change the structure and regenerate the code, and you are off again.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
I could go on and on about it. I had written a series of VB6 addins which I used based
off Rocky Lhotka's BusinessObjects book for VB5. In hours I could generate almost
all of my middle and data tier code. A tweak here and there, and I was doing the fun
stuff like UI coding. 
&lt;/p&gt;
&lt;p&gt;
Along comes .Net, and my addins were irrelevant. I created a couple of quick and dirty
addins, but I was so busy heads-down coding, I didn't have time to create new templates
to reflect the impact of .Net. I did create some common libraries of functions which
got me through a good chunk of redundant coding, so that was going to have to do the
job for the time.&amp;nbsp; I had always intended on going back and re-coding some new
templates, but it never happened. 
&lt;/p&gt;
&lt;p&gt;
I am currently working on a project and we are horribly understaffed, and there's
no relief in sight. There are some huge deadlines coming up, and it's time to make
the rubber hit the road. I already code fast (and tight), but I needed to clone myself
a couple times over to make the deadlines. So when the announcement came this week
of CodeSmith 3.0, I decided I would take a new serious look at it and see what it
could do for me. 
&lt;/p&gt;
&lt;p&gt;
Holy crap! In a matter of hours I had some pretty solid templates up and running,
which will save the team many, many hours of redundant coding tasks in building this
application. I have so many ideas for new templates it's scary, and&amp;nbsp;I have only
scratched the surface for what the tool can do. If you haven't looked at it yet, I
recommend immediately going to &lt;a href="http://www.codesmithtools.com/" target=_blank&gt;CodeSmith&lt;/a&gt; and
downloading a trial.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=9371af86-0405-4beb-bd2e-b0b1f0884ae1" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,9371af86-0405-4beb-bd2e-b0b1f0884ae1.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=14bee00c-2e56-4024-ba74-c52a804be4c5</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,14bee00c-2e56-4024-ba74-c52a804be4c5.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,14bee00c-2e56-4024-ba74-c52a804be4c5.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=14bee00c-2e56-4024-ba74-c52a804be4c5</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
If you are using DIME attachments, and you want to use them in a Windows client, this
tip will save you some time. I created a File Upload/Download web service for a client
I am currently working with, and until this week is was used solely on a web front
end. However, there was a request for a Windows client, so I set out to create one
using the same code. 
</p>
        <p>
All seemed well, until I went to compile. My Web Service is called FileService (for
the purposes of this discussion), and in order the use DIME attachments after setting
a web reference, you need to use the FileServiceWse version of the web reference (the
wse class). The problem was, one wasn't generated in the proxy. I debated using the
proxy for the web application, but then decided to try something a little different.
</p>
        <p>
I removed the existing Web Reference, added a reference to System.Web to my project,
then added the Web Reference again. Viola! My wse version was available now, and my
code compiles! I decided to post this to save someone else a bit of time, as well
as a reminder to myself in the future.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=14bee00c-2e56-4024-ba74-c52a804be4c5" />
      </body>
      <title>Tip of the day: Using Web Services in a Windows environment </title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,14bee00c-2e56-4024-ba74-c52a804be4c5.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/04/23/TipOfTheDayUsingWebServicesInAWindowsEnvironment.aspx</link>
      <pubDate>Sat, 23 Apr 2005 20:36:27 GMT</pubDate>
      <description>&lt;p&gt;
If you are using DIME attachments, and you want to use them in a Windows client, this
tip will save you some time. I created a File Upload/Download web service for a client
I am currently working with, and until this week is was used solely on a web front
end. However, there was a request for a Windows client, so I set out to create one
using the same code. 
&lt;/p&gt;
&lt;p&gt;
All seemed well, until I went to compile. My Web Service is called FileService (for
the purposes of this discussion), and in order the use DIME attachments after setting
a web reference, you need to use the FileServiceWse version of the web reference (the
wse class). The problem was, one wasn't generated in the proxy. I debated using the
proxy for the web application, but then decided to try something a little different.
&lt;/p&gt;
&lt;p&gt;
I removed the existing Web Reference, added a reference to System.Web to my project,
then added the Web Reference again. Viola! My wse version was available now, and my
code compiles! I decided to post this to save someone else a bit of time, as well
as a reminder to myself in the future.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=14bee00c-2e56-4024-ba74-c52a804be4c5" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,14bee00c-2e56-4024-ba74-c52a804be4c5.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>VB.Net</category>
      <category>Windows</category>
      <category>WinForms</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
There's a lot of debate on the best type of error handling, where to log it (if at
all), and when to do it. For example, here's a debate today:
</p>
        <p>
          <a href="http://weblogs.asp.net/alex_papadimoulis/archive/2005/03/29/396141.aspx">http://weblogs.asp.net/alex_papadimoulis/archive/2005/03/29/396141.aspx</a>
        </p>
        <p>
In this debate, the question is Return codes vs. Throwing an Exception. You can read
the blog entry to see the debate. Here's my take, and why.
</p>
        <p>
First, I always handle the exception where it happens, and rarely bubble it up. Why?
First, what if the calling code doesn't handle the exception? Now you have an unhandled
error, and it could cause an application to crash. On a recent project for a large
chipmaking client, I got into this debate a few times with all levels of developers.
It was always an interesting debate with senior developers because they at least adopted
their belief into action and a bigger strategy. For example, they may trickle it up
and handle it at the highest level, but if they forget to handle it, the best developers
handle the uncaught errors at the thread level. The advantage is they have the error
information and can use it to provide the user some feedback as to the nature of the
problem.
</p>
        <p>
But those are good developers, and I would say the top 10%. As an example, I had this
debate with a mid-level developer who was convinced he was a senior level developer.
Now, as I tell this story, let me mention I am a very good poker player. He adamantly
felt errors should be bubbled up and handled at the UI. I countered him with the standard
“What happens when the exception isn't handled?” He advised me he never
forgets. Enter the poker player in me. 
</p>
        <p>
Being a consultant, you have to know when to shut up and let the “hand”
play out. This was an XP project (never again), and as we paired, I watched him write
some code, and I even reminded him about error handling. For the most part, with my
diligence and because we had just had the discussion this guy was being fairly consistant
in his exception handling at the UI level. However, I stopped reminding him (it's
instinct for me to do it now), and sure enough, he forgot, and the application crashed
a horrible death. The reason I wanted to have this discussion with him was because
his code was causing about 80% of the crashes on the team, and I was trying to help
him improve his skills (and our project). To finish the story, the guy's ego was so
big he refused to accept responsibility for the crashes or even acknowledge that I
had a valid point about forgetting error handling, and kept on his merry way.
</p>
        <p>
Back to the point, IMHO error handling should be handled where the error occurs. This
is especially true in multi-developer projects, as you cannot guarantee someone who
calls your code is diligent enough to handle things when problems occur.
</p>
        <p>
But that has a serious downside -- how do you let the user know there was a problem,
and it was handled? The answer -- return values. OK, there's a little more to it than
that. An error code is never enough information to provide feedback or to decide what
to do when the caller receives notice an error occurred. Even worse, a number is useless
in trying to relay relevant info to the end-user.
</p>
        <p>
What I have adopted is this: I have a base class which my other classes inherit from.
In that class, I have an ErrorMessage property (string) which is set where the error
occurs, or in a central error handler. When a method encounters an error, it returns
an integer value indicating failure. The calling routine (if desired) can check the
ErrorMessage property and use that value for displaying a message or get details as
to the nature of the problem.  It can also ignore it if it wants. The key thing
though is that the error will never go unhandled and cause the application to crash.
</p>
        <p>
I'll be happy to post up some examples if there is interest. This is just a very important
topic to me, and one I think which separates the wheat from the chaff, as they say!
</p>
        <p>
In the debate listed above, there's an argument over performance. There's a balance
here: you need to perform well, but performance is killed when the application
crashes. Find a solution which is robust but also performs. Not handling an exception
is not an option for robustness.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75" />
      </body>
      <title>Error Handling Discussion</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/04/14/ErrorHandlingDiscussion.aspx</link>
      <pubDate>Thu, 14 Apr 2005 16:49:54 GMT</pubDate>
      <description>&lt;p&gt;
There's a lot of debate on the best type of error handling, where to log it (if at
all), and when to do it. For example, here's a debate today:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://weblogs.asp.net/alex_papadimoulis/archive/2005/03/29/396141.aspx"&gt;http://weblogs.asp.net/alex_papadimoulis/archive/2005/03/29/396141.aspx&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
In this debate, the question is Return codes vs. Throwing an Exception. You can read
the blog entry to see the debate. Here's my take, and why.
&lt;/p&gt;
&lt;p&gt;
First, I always handle the exception where it happens, and rarely bubble it up. Why?
First, what if the calling code doesn't handle the exception? Now you have an unhandled
error, and it could cause an application to crash. On a recent project for a large
chipmaking client, I got into this debate a few times with all levels of developers.
It was always an interesting debate with senior developers because they at least adopted
their belief into action and a bigger strategy. For example, they may trickle it up
and handle it at the highest level, but if they forget to handle it, the best developers
handle the uncaught errors at the thread level. The advantage is they have the error
information and can use it to provide the user some feedback as to the nature of the
problem.
&lt;/p&gt;
&lt;p&gt;
But those are good developers, and I would say the top 10%. As an example, I had this
debate with a mid-level developer who was convinced he was a senior level developer.
Now, as I tell this story, let me mention I am a very good poker player. He adamantly
felt errors should be bubbled up and handled at the UI. I countered him with the standard
&amp;#8220;What happens when the exception isn't handled?&amp;#8221; He advised me he never
forgets. Enter the poker player in me. 
&lt;/p&gt;
&lt;p&gt;
Being a consultant, you have to know when to shut up and let the &amp;#8220;hand&amp;#8221;
play out. This was an XP project (never again), and as we paired, I watched him write
some code, and I even reminded him about error handling. For the most part, with my
diligence and because we had just had the discussion this guy was being fairly consistant
in his exception handling at the UI level. However, I stopped reminding him (it's
instinct for me to do it now), and sure enough, he forgot, and the application crashed
a horrible death. The reason I wanted to have this discussion with him was because
his code was causing about 80% of the crashes on the team, and I was trying to help
him improve his skills (and our project). To finish the story, the guy's ego was so
big he refused to accept responsibility for the crashes or even acknowledge that I
had a valid point about forgetting error handling, and kept on his merry way.
&lt;/p&gt;
&lt;p&gt;
Back to the point, IMHO error handling should be handled where the error occurs. This
is especially true in multi-developer projects, as you cannot guarantee someone who
calls your code is diligent enough to handle things when problems occur.
&lt;/p&gt;
&lt;p&gt;
But that has a serious downside -- how do you let the user know there was a problem,
and it was handled? The answer -- return values. OK, there's a little more to it than
that. An error code is never enough information to provide feedback or to decide what
to do when the caller receives notice an error occurred. Even worse, a number is useless
in trying to relay relevant info to the end-user.
&lt;/p&gt;
&lt;p&gt;
What I have adopted is this: I have a base class which my other classes inherit from.
In that class, I have an ErrorMessage property (string) which is set where the error
occurs, or in a central error handler. When a method encounters an error, it returns
an integer value indicating failure. The calling routine (if desired) can check the
ErrorMessage property and use that value for displaying a message or get details as
to the nature of the problem.&amp;nbsp; It can also ignore it if it wants. The key thing
though is that the error will never go unhandled and cause the application to crash.
&lt;/p&gt;
&lt;p&gt;
I'll be happy to post up some examples if there is interest. This is just a very important
topic to me, and one I think which separates the wheat from the chaff, as they say!
&lt;/p&gt;
&lt;p&gt;
In the debate listed above, there's an argument over performance. There's a balance
here: you need to perform well, but performance is killed&amp;nbsp;when the application
crashes. Find a solution which is robust but also performs. Not handling an exception
is not an option for robustness.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,8e3e7285-b4a7-4a3a-910c-1a84d2b1cf75.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=d5411609-078a-494c-9e9d-7d01f80c3f51</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,d5411609-078a-494c-9e9d-7d01f80c3f51.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,d5411609-078a-494c-9e9d-7d01f80c3f51.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=d5411609-078a-494c-9e9d-7d01f80c3f51</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I have a large ASP.Net project I am working on, and the solution contains about 6
projects. Periodically, it won't compile, but when I look in the Task List there are
no errors listed. After a lot of trial and error, I finally found a solution which
restores the missing error notations, so that I can fix the problem and move on.
</p>
        <p>
Right-click in the “Task” screen, and select the “Show Tasks/Comments”
option. Try compiling, and of course it will fail again. Then, right-click on the
“Task” screen again, and select the “Build Errors” option,
and they should appear. It seems to work fairly consistantly so I think this “workaround”
may actually work.
</p>
        <p>
As an alternative (although not as easy to work with), you can just look at the output
window, and filter through the text output. Take your pick, you should be able to
see what the problem is!
</p>
        <p>
ADDENDUM: It happened again, and these steps didn't work exactly. To make it work,
try to compile again between “right-clicks” and they should appear.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=d5411609-078a-494c-9e9d-7d01f80c3f51" />
      </body>
      <title>Tip of the Day - My errors aren't showing up in the task list..???</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,d5411609-078a-494c-9e9d-7d01f80c3f51.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/04/04/TipOfTheDayMyErrorsArentShowingUpInTheTaskList.aspx</link>
      <pubDate>Mon, 04 Apr 2005 18:28:35 GMT</pubDate>
      <description>&lt;p&gt;
I have a large ASP.Net project I am working on, and the solution contains about 6
projects. Periodically, it won't compile, but when I look in the Task List there are
no errors listed. After a lot of trial and error, I finally found a solution which
restores the missing error notations, so that I can fix the problem and move on.
&lt;/p&gt;
&lt;p&gt;
Right-click in the &amp;#8220;Task&amp;#8221; screen, and select the &amp;#8220;Show Tasks/Comments&amp;#8221;
option. Try compiling, and of course it will fail again. Then, right-click on the
&amp;#8220;Task&amp;#8221; screen again, and select the &amp;#8220;Build Errors&amp;#8221; option,
and they should appear. It seems to work fairly consistantly so I think this &amp;#8220;workaround&amp;#8221;
may actually work.
&lt;/p&gt;
&lt;p&gt;
As an alternative (although not as easy to work with), you can just look at the output
window, and filter through the text output. Take your pick, you should be able to
see what the problem is!
&lt;/p&gt;
&lt;p&gt;
ADDENDUM: It happened again, and these steps didn't work exactly. To make it work,
try to compile again between &amp;#8220;right-clicks&amp;#8221; and they should appear.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=d5411609-078a-494c-9e9d-7d01f80c3f51" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,d5411609-078a-494c-9e9d-7d01f80c3f51.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>CSharp</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>VB.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=41506101-3710-4682-8821-965a563fd77b</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,41506101-3710-4682-8821-965a563fd77b.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,41506101-3710-4682-8821-965a563fd77b.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=41506101-3710-4682-8821-965a563fd77b</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Sometimes as a developer you need to rename a file with a date time aspect
so you can do something like guarantee uniqueness,  track submission information,
etc. There's always a ton of ways to do this, but I decided to write a couple of routines
to do this using the FileInfo class. First, the code:
</p>
        <div style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 0pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 0pt; FONT-SIZE: 10pt; BACKGROUND: white; PADDING-BOTTOM: 0pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 0pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New">
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">///</span>
            <span style="COLOR: green">
            </span>
            <span style="COLOR: gray">&lt;summary&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">///</span>
            <span style="COLOR: green"> Gets a string you
can append in a file name to supply uniqueness</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">///</span>
            <span style="COLOR: green">
            </span>
            <span style="COLOR: gray">&lt;/summary&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">///</span>
            <span style="COLOR: green">
            </span>
            <span style="COLOR: gray">&lt;returns&gt;</span>
            <span style="COLOR: green">a
string which looks similar to 2232005_090812 which is a date time</span>
            <span style="COLOR: gray">&lt;/returns&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">static</span>
            <span style="COLOR: blue">string</span> GetUniqueFileNameIdentifier()
</p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span> DateTime.Now.Month.ToString()
+ DateTime.Now.Day.ToString() + DateTime.Now.Year.ToString()+ "_" + DateTime.Now.Hour.ToString()
+ DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
</p>
          <p style="MARGIN: 0px">
}
</p>
          <p style="MARGIN: 0px">
 
</p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">///</span>
            <span style="COLOR: green">
            </span>
            <span style="COLOR: gray">&lt;summary&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">///</span>
            <span style="COLOR: green"> Renames a file with
a unique identifier in it</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">///</span>
            <span style="COLOR: green">
            </span>
            <span style="COLOR: gray">&lt;/summary&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">///</span>
            <span style="COLOR: green">
            </span>
            <span style="COLOR: gray">&lt;param
name="fileName"&gt;</span>
            <span style="COLOR: green">file name to rename..</span>
            <span style="COLOR: gray">&lt;/param&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: gray">///</span>
            <span style="COLOR: green">
            </span>
            <span style="COLOR: gray">&lt;returns&gt;</span>
            <span style="COLOR: green">unique
name of file with datetime identifier in the name. e.g. MyFile.txt renamed to MyFile_2232005_090812.txt </span>
            <span style="COLOR: gray">&lt;/returns&gt;</span>
          </p>
          <p style="MARGIN: 0px">
            <span style="COLOR: blue">public</span>
            <span style="COLOR: blue">static</span>
            <span style="COLOR: blue">string</span> FormatUniqueFileName(<span style="COLOR: blue">string</span> fileName)
</p>
          <p style="MARGIN: 0px">
{
</p>
          <p style="MARGIN: 0px">
    FileInfo fi = <span style="COLOR: blue">new</span> FileInfo(fileName);
</p>
          <p style="MARGIN: 0px">
    <span style="COLOR: blue">return</span> fi.Name.Replace(fi.Extension,"")
+ "_" + GetUniqueFileNameIdentifier() + fi.Extension;
</p>
          <p style="MARGIN: 0px">
}
</p>
        </div>
        <p>
First, the FormatUniqueFileName funtion takes a file name (like test.txt), and inserts
the date time info (in the current format, it does this as fileprefix_mmddyyyy_hhmmss.fileextension,
so in our example, we might get test_03162005_071525.txt.
</p>
        <p>
Not a real complex function by any means, but one that's reused a lot in development,
and I decided to get this out just in case some developer wanted to save 5 minutes!
</p>
        <p>
Enjoy!<!--EndFragment--></p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=41506101-3710-4682-8821-965a563fd77b" />
      </body>
      <title>Tip of the day: Renaming files with a time date stamp</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,41506101-3710-4682-8821-965a563fd77b.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/03/16/TipOfTheDayRenamingFilesWithATimeDateStamp.aspx</link>
      <pubDate>Wed, 16 Mar 2005 15:26:57 GMT</pubDate>
      <description>&lt;p&gt;
Sometimes&amp;nbsp;as a developer you need to rename a file with a date&amp;nbsp;time aspect
so you can do something like guarantee uniqueness, &amp;nbsp;track submission information,
etc. There's always a ton of ways to do this, but I decided to write a couple of routines
to&amp;nbsp;do this using the FileInfo class. First, the code:
&lt;/p&gt;
&lt;div style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 0pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 0pt; FONT-SIZE: 10pt; BACKGROUND: white; PADDING-BOTTOM: 0pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 0pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Gets a string you
can append in a file name to supply uniqueness&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;a
string which looks similar to 2232005_090812 which is a date time&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; GetUniqueFileNameIdentifier()
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; DateTime.Now.Month.ToString()
+ DateTime.Now.Day.ToString() + DateTime.Now.Year.ToString()+ "_" + DateTime.Now.Hour.ToString()
+ DateTime.Now.Minute.ToString() + DateTime.Now.Second.ToString();
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; Renames a file with
a unique identifier in it&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/summary&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;param
name="fileName"&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;file name to rename..&lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/param&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: gray"&gt;///&lt;/span&gt;&lt;span style="COLOR: green"&gt; &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;returns&amp;gt;&lt;/span&gt;&lt;span style="COLOR: green"&gt;unique
name of file with datetime identifier in the name. e.g. MyFile.txt renamed to MyFile_2232005_090812.txt &lt;/span&gt;&lt;span style="COLOR: gray"&gt;&amp;lt;/returns&amp;gt;&lt;/span&gt;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; FormatUniqueFileName(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; fileName)
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
{
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; FileInfo fi = &lt;span style="COLOR: blue"&gt;new&lt;/span&gt; FileInfo(fileName);
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; fi.Name.Replace(fi.Extension,"")
+ "_" + GetUniqueFileNameIdentifier() + fi.Extension;
&lt;/p&gt;
&lt;p style="MARGIN: 0px"&gt;
}
&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;
First, the FormatUniqueFileName funtion takes a file name (like test.txt), and inserts
the date time info (in the current format, it does this as fileprefix_mmddyyyy_hhmmss.fileextension,
so in our example, we might get test_03162005_071525.txt.
&lt;/p&gt;
&lt;p&gt;
Not a real complex function by any means, but one that's reused a lot in development,
and I decided to get this out just in case some developer wanted to save 5 minutes!
&lt;/p&gt;
&lt;p&gt;
Enjoy!&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=41506101-3710-4682-8821-965a563fd77b" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,41506101-3710-4682-8821-965a563fd77b.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=80e3aae3-25f7-4fcb-ba45-62e0879ecc72</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,80e3aae3-25f7-4fcb-ba45-62e0879ecc72.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,80e3aae3-25f7-4fcb-ba45-62e0879ecc72.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=80e3aae3-25f7-4fcb-ba45-62e0879ecc72</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
I am currently trying to go through a Code Review at a large bank to get our code
approved for release on the internet. One thing that came up was in some situations,
we are displaying the raw exception message which was listed as a no-no, which I disagree
with. While it's not particularly informative to the user which is potentially an
issue, I can't see where “Invalid use of null” is going to be particularly
useful to a hacker, but to a developer, that tidbit may help identify the problem
when the user calls for help (good application logging aside in this example). Ironically,
when errors weren't handled because the developer forgot, this passed code review.
</p>
        <p>
So my intent was to enumerate all the default error messages to determine if there
are any which would be particularly helpful to a hacker. While I am still looking
to find or create an application which will enumerate all the default messages that
.New throws out, I did come across a great article which lists the various error handling
philosophies, and tries to weigh out the pros and cons of each. Here's where to get
this pearl of wisdom:
</p>
        <p>
          <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/exceptdotnet.asp">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/exceptdotnet.asp</a>
        </p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=80e3aae3-25f7-4fcb-ba45-62e0879ecc72" />
      </body>
      <title>Tip of the Day -- Great Exception Handling article</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,80e3aae3-25f7-4fcb-ba45-62e0879ecc72.aspx</guid>
      <link>http://www.dotnettechnologies.com/2005/03/09/TipOfTheDayGreatExceptionHandlingArticle.aspx</link>
      <pubDate>Wed, 09 Mar 2005 17:47:50 GMT</pubDate>
      <description>&lt;p&gt;
I am currently trying to go through a Code Review at a large bank to get our code
approved for release on the internet. One thing that came up was in some situations,
we are displaying the raw exception message which was listed as a no-no, which I disagree
with. While it's not particularly informative to the user which is potentially an
issue, I can't see where &amp;#8220;Invalid use of null&amp;#8221; is going to be particularly
useful to a hacker, but to a developer, that tidbit may help identify the problem
when the user calls for help (good application logging aside in this example). Ironically,
when errors weren't handled because the developer forgot, this passed code review.
&lt;/p&gt;
&lt;p&gt;
So my intent was to enumerate all the default error messages to determine if there
are any which would be particularly helpful to a hacker. While I am still looking
to find or create an application which will enumerate all the default messages that
.New throws out, I did come across a great article which lists the various error handling
philosophies, and tries to weigh out the pros and cons of each. Here's where to get
this pearl of wisdom:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/exceptdotnet.asp"&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnbda/html/exceptdotnet.asp&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=80e3aae3-25f7-4fcb-ba45-62e0879ecc72" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,80e3aae3-25f7-4fcb-ba45-62e0879ecc72.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>Design</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>VB.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=1509924c-e48d-4d6e-8af0-4562186eacfd</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,1509924c-e48d-4d6e-8af0-4562186eacfd.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,1509924c-e48d-4d6e-8af0-4562186eacfd.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=1509924c-e48d-4d6e-8af0-4562186eacfd</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here's another simple tip, but it does encapsulate some of the functionality needed
to format a DateTime (or a string) to a particular string format. First, from the
documentation, here's some examples of the DateTime formatting:
</p>
        <p>
          <strong>Column 1: Format String, Column 2: The format of the date</strong>
          <br />
          <font color="#0000ff">    ' d :08/17/2000<br />
    ' D :Thursday, August 17, 2000<br />
    ' f :Thursday, August 17, 2000 16:32<br />
    ' F :Thursday, August 17, 2000 16:32:32<br />
    ' g :08/17/2000 16:32<br />
    ' G :08/17/2000 16:32:32<br />
    ' m :August 17<br />
    ' r :Thu, 17 Aug 2000 23:32:32 GMT<br />
    ' s :2000-08-17T16:32:32<br />
    ' t :16:32<br />
    ' T :16:32:32<br />
    ' u :2000-08-17 23:32:32Z<br />
    ' U :Thursday, August 17, 2000 23:32:32<br />
    ' y :August, 2000<br />
    ' dddd, MMMM dd yyyy :Thursday, August 17 2000<br />
    ' ddd, MMM d "'"yy :Thu, Aug 17 '00<br />
    ' dddd, MMMM dd :Thursday, August 17<br />
    ' M/yy :8/00<br />
    ' dd-MM-yy :17-08-00</font>
        </p>
        <p>
          <font color="#0000ff">
            <font color="#000000">First, we'll need a function to verify
the string we have is a valid date. </font>
          </font>
        </p>
        <div style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 0pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 0pt; FONT-SIZE: 10pt; BACKGROUND: white; PADDING-BOTTOM: 0pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 0pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New">   
    <span style="COLOR: blue">public</span><span style="COLOR: blue">static</span><span style="COLOR: blue">bool</span> ValidDate(<span style="COLOR: blue">string</span> checkDate)<br />
        {<br />
            <span style="COLOR: blue">try</span><br />
            {<br />
                DateTime
dtTemp;<br />
                dtTemp
= DateTime.Parse(checkDate);<br />
                <span style="COLOR: blue">return</span><span style="COLOR: blue">true</span>;<br />
            }<br />
            <span style="COLOR: blue">catch</span><br />
            {<br />
                <span style="COLOR: blue">return</span><span style="COLOR: blue">false</span>;<br />
            }<br />
        }<br /></div>
        <p>
The ValidDate function takes a string, and returns true if the value is a valid date,
or false if it isn't.
</p>
        <p>
Next, here's the function for formatting the date:
</p>
        <div style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 0pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 0pt; FONT-SIZE: 10pt; BACKGROUND: white; PADDING-BOTTOM: 0pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 0pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New">
          <span style="COLOR: blue">public</span>
          <span style="COLOR: blue">static</span>
          <span style="COLOR: blue">string</span> FormatDateTimeCustom(<span style="COLOR: blue">string</span> valDate, <span style="COLOR: blue">string</span> formatString)<br />
{<br />
    <span style="COLOR: blue">if</span> (ValidDate(valDate))<br />
        <span style="COLOR: blue">return</span> Convert.ToDateTime(valDate).ToString(formatString);<br />
    <span style="COLOR: blue">else</span><br />
        <span style="COLOR: blue">return</span> valDate;<br />
}<br /></div>
        <p>
valDate = the string to format
</p>
        <p>
formatString = the format style as listed earlier
</p>
        <p>
That's it for today!<!--EndFragment--></p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=1509924c-e48d-4d6e-8af0-4562186eacfd" />
      </body>
      <title>Tip of the Day: Formatting Dates</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,1509924c-e48d-4d6e-8af0-4562186eacfd.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/12/28/TipOfTheDayFormattingDates.aspx</link>
      <pubDate>Tue, 28 Dec 2004 17:07:14 GMT</pubDate>
      <description>&lt;p&gt;
Here's another simple tip, but it does encapsulate some of the functionality needed
to format a DateTime (or a string) to a particular string format. First, from the
documentation, here's some examples of the DateTime formatting:
&lt;/p&gt;
&lt;p&gt;
&lt;strong&gt;Column 1: Format String, Column 2: The format of the date&lt;/strong&gt;
&lt;br&gt;
&lt;font color=#0000ff&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; ' d :08/17/2000&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' D :Thursday, August 17, 2000&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' f :Thursday, August 17, 2000 16:32&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' F :Thursday, August 17, 2000 16:32:32&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' g :08/17/2000 16:32&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' G :08/17/2000 16:32:32&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' m :August 17&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' r :Thu, 17 Aug 2000 23:32:32 GMT&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' s :2000-08-17T16:32:32&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' t :16:32&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' T :16:32:32&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' u :2000-08-17 23:32:32Z&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' U :Thursday, August 17, 2000 23:32:32&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' y :August, 2000&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' dddd, MMMM dd yyyy :Thursday, August 17 2000&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' ddd, MMM d "'"yy :Thu, Aug 17 '00&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' dddd, MMMM dd :Thursday, August 17&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' M/yy :8/00&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; ' dd-MM-yy :17-08-00&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#0000ff&gt;&lt;font color=#000000&gt;First, we'll need a function to verify the
string we have is a valid date. &lt;/font&gt;&lt;/font&gt;
&lt;/p&gt;
&gt;&gt; 
&lt;div style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 0pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 0pt; FONT-SIZE: 10pt; BACKGROUND: white; PADDING-BOTTOM: 0pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 0pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;bool&lt;/span&gt; ValidDate(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; checkDate)&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;try&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&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; DateTime
dtTemp;&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; dtTemp
= DateTime.Parse(checkDate);&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; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;true&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;catch&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; {&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; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; &lt;span style="COLOR: blue"&gt;false&lt;/span&gt;;&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br&gt;
&lt;/div&gt;
&lt;p&gt;
The ValidDate function takes a string, and returns true if the value is a valid date,
or false if it isn't.
&lt;/p&gt;
&lt;p&gt;
Next, here's the function for formatting the date:
&lt;/p&gt;
&lt;div style="BORDER-RIGHT: windowtext 1pt solid; PADDING-RIGHT: 0pt; BORDER-TOP: windowtext 1pt solid; PADDING-LEFT: 0pt; FONT-SIZE: 10pt; BACKGROUND: white; PADDING-BOTTOM: 0pt; BORDER-LEFT: windowtext 1pt solid; COLOR: black; PADDING-TOP: 0pt; BORDER-BOTTOM: windowtext 1pt solid; FONT-FAMILY: Courier New"&gt;&lt;span style="COLOR: blue"&gt;public&lt;/span&gt; &lt;span style="COLOR: blue"&gt;static&lt;/span&gt; &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; FormatDateTimeCustom(&lt;span style="COLOR: blue"&gt;string&lt;/span&gt; valDate, &lt;span style="COLOR: blue"&gt;string&lt;/span&gt; formatString)&lt;br&gt;
{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;if&lt;/span&gt; (ValidDate(valDate))&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; Convert.ToDateTime(valDate).ToString(formatString);&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;else&lt;/span&gt;
&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;span style="COLOR: blue"&gt;return&lt;/span&gt; valDate;&lt;br&gt;
}&lt;br&gt;
&lt;/div&gt;
&lt;p&gt;
valDate = the string to format
&lt;/p&gt;
&lt;p&gt;
formatString = the format style as listed earlier
&lt;/p&gt;
&lt;p&gt;
That's it for today!&lt;!--EndFragment--&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=1509924c-e48d-4d6e-8af0-4562186eacfd" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,1509924c-e48d-4d6e-8af0-4562186eacfd.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>General</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=69344e13-41ae-43dc-8743-f896052ebd1f</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,69344e13-41ae-43dc-8743-f896052ebd1f.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,69344e13-41ae-43dc-8743-f896052ebd1f.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=69344e13-41ae-43dc-8743-f896052ebd1f</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Say what you will about VB, it does have some wrappers for some neat functions. One
of my favorites is the Split function. Essentially, it takes a string, a parse character
parameter, and returns a string array of the items. For example, it might look like
string[] mystring = Split(myCommaDelimitedString,”,”);
</p>
        <p>
          <font color="#0033cc">So here's what the code looks like:</font>
        </p>
        <p>
          <font color="#0033cc">  /// &lt;summary&gt;<br />
  /// Replacement in C# of the VB.Net split function<br />
  /// &lt;/summary&gt;<br />
  /// &lt;param name="baseString"&gt;string to parse&lt;/param&gt;<br />
  /// &lt;param name="splitChar"&gt;chanracter to parse with &lt;/param&gt;<br />
  /// &lt;returns&gt;&lt;/returns&gt;<br />
  public static string[] Split(string baseString, string splitChar)<br />
  {<br />
   char[] sep = {(splitChar.ToCharArray())[0]};<br />
   return baseString.Split(sep);<br />
  }</font>
        </p>
        <p>
Now, I know you can use the string object's split functionality to do the same thing.
However, those coming out of the VB world will appreciate the encapsulation, as well
as never having to remember the syntax for pre-defining a character array.
</p>
        <p>
 
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=69344e13-41ae-43dc-8743-f896052ebd1f" />
      </body>
      <title>Implementing the Split function in C#</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,69344e13-41ae-43dc-8743-f896052ebd1f.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/12/20/ImplementingTheSplitFunctionInC.aspx</link>
      <pubDate>Mon, 20 Dec 2004 21:13:55 GMT</pubDate>
      <description>&lt;p&gt;
Say what you will about VB, it does have some wrappers for some neat functions. One
of my favorites is the Split function. Essentially, it takes a string, a parse character
parameter, and returns a string array of the items. For example, it might look like
string[] mystring = Split(myCommaDelimitedString,&amp;#8221;,&amp;#8221;);
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#0033cc&gt;So here's what the code looks like:&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#0033cc&gt;&amp;nbsp;&amp;nbsp;/// &amp;lt;summary&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;/// Replacement in C# of the VB.Net split function&lt;br&gt;
&amp;nbsp;&amp;nbsp;/// &amp;lt;/summary&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;/// &amp;lt;param name="baseString"&amp;gt;string to parse&amp;lt;/param&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;/// &amp;lt;param name="splitChar"&amp;gt;chanracter to parse with &amp;lt;/param&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;/// &amp;lt;returns&amp;gt;&amp;lt;/returns&amp;gt;&lt;br&gt;
&amp;nbsp;&amp;nbsp;public static string[] Split(string baseString, string splitChar)&lt;br&gt;
&amp;nbsp;&amp;nbsp;{&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;char[] sep = {(splitChar.ToCharArray())[0]};&lt;br&gt;
&amp;nbsp;&amp;nbsp;&amp;nbsp;return baseString.Split(sep);&lt;br&gt;
&amp;nbsp;&amp;nbsp;}&lt;/font&gt;
&lt;/p&gt;
&lt;p&gt;
Now, I know you can use the string object's split functionality to do the same thing.
However, those coming out of the VB world will appreciate the encapsulation, as well
as never having to remember the syntax for pre-defining a character array.
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=69344e13-41ae-43dc-8743-f896052ebd1f" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,69344e13-41ae-43dc-8743-f896052ebd1f.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=9fd1a674-dc81-412e-b5cd-70b2467c00b7</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,9fd1a674-dc81-412e-b5cd-70b2467c00b7.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,9fd1a674-dc81-412e-b5cd-70b2467c00b7.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=9fd1a674-dc81-412e-b5cd-70b2467c00b7</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
One of the things I use this blog for is to keep track of tips which I may need while
out at the client site. I have a fairly extensive CodeLib library I use, but for some
reason, I didn't have this in my library. 
</p>
        <p>
If you're new to javascript, which I am definitely still in the learning stages of,
at some point you are going to access the control which called a function. I did a
few searches, and it turns out, unless you know what you are looking for, it's tough
to do a search like “javascript determining control which called a function”
and similar searches. So here goes, and hopefully this simple tip will save another
developer a little time. It IS a basic function, I will be the first to admit, but
it is also useful to know for an ASP.Net developer. And the code is:
</p>
        <p>
document.activeElement
</p>
        <p>
There you go! Simple, but for some reason, it's assumed you should know it, which
to a degree, I agree with. But I would also have to say online there seems to be an
assumption that everyone already knows the DOM!
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=9fd1a674-dc81-412e-b5cd-70b2467c00b7" />
      </body>
      <title>Tip of the day - Javascript - Getting the control which called a function</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,9fd1a674-dc81-412e-b5cd-70b2467c00b7.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/12/18/TipOfTheDayJavascriptGettingTheControlWhichCalledAFunction.aspx</link>
      <pubDate>Sat, 18 Dec 2004 21:55:17 GMT</pubDate>
      <description>&lt;p&gt;
One of the things I use this blog for is to keep track of tips which I may need while
out at the client site. I have a fairly extensive CodeLib library I use, but for some
reason, I didn't have this in my library. 
&lt;/p&gt;
&lt;p&gt;
If you're new to javascript, which I am definitely still in the learning stages of,
at some point you are going to access the control which called a function. I did a
few searches, and it turns out, unless you know what you are looking for, it's tough
to do a search like &amp;#8220;javascript determining control which called a function&amp;#8221;
and similar searches. So here goes, and hopefully this simple tip will save another
developer a little time. It IS a basic function, I will be the first to admit, but
it is also useful to know for an ASP.Net developer. And the code is:
&lt;/p&gt;
&lt;p&gt;
document.activeElement
&lt;/p&gt;
&lt;p&gt;
There you go! Simple, but for some reason, it's assumed you should know it, which
to a degree, I agree with. But I would also have to say online there seems to be an
assumption that everyone already knows the DOM!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=9fd1a674-dc81-412e-b5cd-70b2467c00b7" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,9fd1a674-dc81-412e-b5cd-70b2467c00b7.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>Tips and Tricks</category>
      <category>VB.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=9e2de6f0-e90a-42f1-a3ee-ac6bf479cf53</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,9e2de6f0-e90a-42f1-a3ee-ac6bf479cf53.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,9e2de6f0-e90a-42f1-a3ee-ac6bf479cf53.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=9e2de6f0-e90a-42f1-a3ee-ac6bf479cf53</wfw:commentRss>
      <slash:comments>4</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Do you have a routine which you know works, and you don't want to have to step into
when you're debugging? Granted, you could you the hotkeys to do it, but why bother?
The System.Diagnostics namespace provides some neat functionality for helping you
in your debugging process. Here's some examples:
</p>
        <p>
//This attribute prevents the debugger from entering, as well as no breakpoints within
</p>
        <p>
&lt;System.Diagnostics.DebuggerStepThrough()&gt; 
</p>
        <p>
private string MyRoutine()
</p>
        <p>
{
</p>
        <p>
//Don't step through this
</p>
        <p>
}
</p>
        <p>
I am actually not sure what the difference between that and the DebuggerHidden() attribute
is though. The description in the help is the same. Anyone know?
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=9e2de6f0-e90a-42f1-a3ee-ac6bf479cf53" />
      </body>
      <title>Skipping over a routine automatically in the debugger, and other neat debugger tricks..</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,9e2de6f0-e90a-42f1-a3ee-ac6bf479cf53.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/12/15/SkippingOverARoutineAutomaticallyInTheDebuggerAndOtherNeatDebuggerTricks.aspx</link>
      <pubDate>Wed, 15 Dec 2004 20:15:13 GMT</pubDate>
      <description>&lt;p&gt;
Do you have a routine which you know works, and you don't want to have to step into
when you're debugging? Granted, you could you the hotkeys to do it, but why bother?
The System.Diagnostics namespace provides some neat functionality for helping you
in your debugging process. Here's some examples:
&lt;/p&gt;
&lt;p&gt;
//This attribute prevents the debugger from entering, as well as no breakpoints within
&lt;/p&gt;
&lt;p&gt;
&amp;lt;System.Diagnostics.DebuggerStepThrough()&amp;gt; 
&lt;/p&gt;
&lt;p&gt;
private string MyRoutine()
&lt;/p&gt;
&lt;p&gt;
{
&lt;/p&gt;
&lt;p&gt;
//Don't step through this
&lt;/p&gt;
&lt;p&gt;
}
&lt;/p&gt;
&lt;p&gt;
I am actually not sure what the difference between that and the DebuggerHidden() attribute
is though. The description in the help is the same. Anyone know?
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=9e2de6f0-e90a-42f1-a3ee-ac6bf479cf53" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,9e2de6f0-e90a-42f1-a3ee-ac6bf479cf53.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>Tips and Tricks</category>
      <category>VB.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=a80953ac-6633-43e2-9e17-6e847ccb94d0</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,a80953ac-6633-43e2-9e17-6e847ccb94d0.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,a80953ac-6633-43e2-9e17-6e847ccb94d0.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=a80953ac-6633-43e2-9e17-6e847ccb94d0</wfw:commentRss>
      <slash:comments>3</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here's a quick tip for casting to a particular type if you have the name of the type.
Once again, it may be obvious to some, but if you've never done it, it's tough to
find a quick example of it, so here goes.
</p>
        <p>
I was implementing a custom ViewState for an UserControl I was creating, and came
across a situation where I needed to dynamically box a type, when all I know is the
type which I have stored in a string. I am creating a special container control which
can host any other type of control, and for restoring ViewState, I needed to cast
it correctly when restored. Fortunately, I followed a hunch, and came across the answer
-- System.Type.GetType.
</p>
        <p>
string testType = “System.Int32“;
</p>
        <p>
Type myType1 = Type.GetType(testType);
</p>
        <p>
Not Earth shattering, but then again, you have to know where to look!<br /></p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=a80953ac-6633-43e2-9e17-6e847ccb94d0" />
      </body>
      <title>Tip of the Day: Dynamically boxing a type in C#</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,a80953ac-6633-43e2-9e17-6e847ccb94d0.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/12/08/TipOfTheDayDynamicallyBoxingATypeInC.aspx</link>
      <pubDate>Wed, 08 Dec 2004 14:49:20 GMT</pubDate>
      <description>&lt;p&gt;
Here's a quick tip for casting to a particular type if you have the name of the type.
Once again, it may be obvious to some, but if you've never done it, it's tough to
find a quick example of it, so here goes.
&lt;/p&gt;
&lt;p&gt;
I was implementing a custom ViewState for an UserControl I was creating, and came
across a situation where I needed to dynamically box a type, when all I know is the
type which I have stored in a string. I am creating a special container control which
can host any other type of control, and for restoring ViewState, I needed to cast
it correctly when restored. Fortunately, I followed a hunch, and came across the answer
-- System.Type.GetType.
&lt;/p&gt;
&lt;p&gt;
string testType = &amp;#8220;System.Int32&amp;#8220;;
&lt;/p&gt;
&lt;p&gt;
Type myType1 = Type.GetType(testType);
&lt;/p&gt;
&lt;p&gt;
Not Earth shattering, but then again, you have to know where to look!&lt;br&gt;
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=a80953ac-6633-43e2-9e17-6e847ccb94d0" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,a80953ac-6633-43e2-9e17-6e847ccb94d0.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=01fdbb59-0e3c-4a8e-b853-662341bab110</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,01fdbb59-0e3c-4a8e-b853-662341bab110.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,01fdbb59-0e3c-4a8e-b853-662341bab110.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=01fdbb59-0e3c-4a8e-b853-662341bab110</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
OK, so you're looking at some really obscure code, so it's time to step in and see
exactly what it's doing, and the best way to do it is use the debugger. Actually,
if I have to give you a reason to use the debugger, you probably shouldn't be reading
this in the first place. You fire up the VS IDE, hit F5, and viola! You see the following
scary message:
</p>
        <p>
          <img height="139" src="http://www.dotnettechnologies.com/DotNetTechnologies/content/binary/failure.jpg" width="551" border="0" />
        </p>
        <p>
What the heck? “Error when typing to run project: Unable to start debugging
on the web server. Catastrophic failure.”
</p>
        <p>
Likely you won't see this unless you don't have Admin privledges on the box. Right
now, I am doing a project for a large bank, and trying to get rights to do anything
is like trying to pry a “Magic” card from a freshman engineering student.
My rights are so messed up, I actually have to do the following steps at the start
of every day I plan on debugging. If you see this message, here's the steps you can
try to get rid of it and get on with your debugging.
</p>
        <p>
First, you're going to need to change one of the local security policies. Open up
your admin folder, and select Local Security Policies. You should see something similar
to the image below. Next, select <em>User Rights Assignment</em>. 
</p>
        <p>
          <img height="537" src="http://www.dotnettechnologies.com/DotNetTechnologies/content/binary/secpol.jpg" width="768" border="0" />
        </p>
        <p>
Locate <em>Impersonate a client after authentication</em>, and double click on it.
You should get a dialog similar to the following. What you'll need to do is add
the IWAM_ (and I add the ASP.Net worker thread just for good measure to the policy)
like below. For the record, I believe only IWAM_ is required.
</p>
        <p>
          <img height="405" src="http://www.dotnettechnologies.com/DotNetTechnologies/content/binary/IWAM.jpg" width="401" border="0" />
        </p>
        <p>
 OK, you've taken the first step to fixing the problem, but that's not it. You've
got to get IIS and the rest of the system to recognize the new policy. So, first,
open up the “Run “ command from the Start menu) or command prompt, and
type the following:
</p>
        <p>
          <img height="179" src="http://www.dotnettechnologies.com/DotNetTechnologies/content/binary/run1.jpg" width="347" border="0" />
        </p>
        <p>
Type 
</p>
        <p>
secedit /refreshpolicy machine_policy /enforce
</p>
        <p>
This will refresh the security policy for the local machine. Next, type this command
to restart IIS now that everything is set.
</p>
        <p>
iisreset
</p>
        <p>
          <img height="179" src="http://www.dotnettechnologies.com/DotNetTechnologies/content/binary/run2.jpg" width="347" border="0" />
        </p>
        <p>
That's it! Assuming the IIS application workspace is set to allow debugging, and everything
else is good on the machine, hopefully you'll be debugging like the Orkin man!
</p>
        <p>
-- Daryl
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=01fdbb59-0e3c-4a8e-b853-662341bab110" />
      </body>
      <title>Castastrophic Error -- What to do when you see this when trying to debug..</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,01fdbb59-0e3c-4a8e-b853-662341bab110.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/12/06/CastastrophicErrorWhatToDoWhenYouSeeThisWhenTryingToDebug.aspx</link>
      <pubDate>Mon, 06 Dec 2004 04:44:29 GMT</pubDate>
      <description>&lt;p&gt;
OK, so you're looking at some really obscure code, so it's time to step in and see
exactly what it's doing, and the best way to do it is use the debugger. Actually,
if I have to give you a reason to use the debugger, you probably shouldn't be reading
this in the first place. You fire up the VS IDE, hit F5, and viola! You see the following
scary message:
&lt;/p&gt;
&lt;p&gt;
&lt;img height=139 src="http://www.dotnettechnologies.com/DotNetTechnologies/content/binary/failure.jpg" width=551 border=0&gt;
&lt;/p&gt;
&lt;p&gt;
What the heck? &amp;#8220;Error when typing to run project: Unable to start debugging
on the web server. Catastrophic failure.&amp;#8221;
&lt;/p&gt;
&lt;p&gt;
Likely you won't see this unless you don't have Admin privledges on the box. Right
now, I am doing a project for a large bank, and trying to get rights to do anything
is like trying to pry a &amp;#8220;Magic&amp;#8221; card from a freshman engineering student.
My rights are so messed up, I actually have to do the following steps at the start
of every day I plan on debugging. If you see this message, here's the steps you can
try to get rid of it and get on with your debugging.
&lt;/p&gt;
&lt;p&gt;
First, you're going to need to change one of the local security policies. Open up
your admin folder, and select Local Security Policies. You should see something similar
to the image below. Next, select &lt;em&gt;User Rights Assignment&lt;/em&gt;. 
&lt;/p&gt;
&lt;p&gt;
&lt;img height=537 src="http://www.dotnettechnologies.com/DotNetTechnologies/content/binary/secpol.jpg" width=768 border=0&gt;
&lt;/p&gt;
&lt;p&gt;
Locate &lt;em&gt;Impersonate a client after authentication&lt;/em&gt;, and double click on it.
You should get a dialog similar to the following. What you'll need to do&amp;nbsp;is add
the IWAM_ (and I add the ASP.Net worker thread just for good measure to the policy)
like below. For the record, I believe only IWAM_ is required.
&lt;/p&gt;
&lt;p&gt;
&lt;img height=405 src="http://www.dotnettechnologies.com/DotNetTechnologies/content/binary/IWAM.jpg" width=401 border=0&gt;
&lt;/p&gt;
&lt;p&gt;
&amp;nbsp;OK, you've taken the first step to fixing the problem, but that's not it. You've
got to get IIS and the rest of the system to recognize the new policy. So, first,
open up the &amp;#8220;Run &amp;#8220; command from the Start menu) or command prompt, and
type the following:
&lt;/p&gt;
&lt;p&gt;
&lt;img height=179 src="http://www.dotnettechnologies.com/DotNetTechnologies/content/binary/run1.jpg" width=347 border=0&gt;
&lt;/p&gt;
&lt;p&gt;
Type 
&lt;/p&gt;
&lt;p&gt;
secedit /refreshpolicy machine_policy /enforce
&lt;/p&gt;
&lt;p&gt;
This will refresh the security policy for the local machine. Next, type this command
to restart IIS now that everything is set.
&lt;/p&gt;
&lt;p&gt;
iisreset
&lt;/p&gt;
&lt;p&gt;
&lt;img height=179 src="http://www.dotnettechnologies.com/DotNetTechnologies/content/binary/run2.jpg" width=347 border=0&gt;
&lt;/p&gt;
&lt;p&gt;
That's it! Assuming the IIS application workspace is set to allow debugging, and everything
else is good on the machine, hopefully you'll be debugging like the Orkin man!
&lt;/p&gt;
&lt;p&gt;
-- Daryl
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=01fdbb59-0e3c-4a8e-b853-662341bab110" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,01fdbb59-0e3c-4a8e-b853-662341bab110.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>C#</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>VB.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=6394fc3f-d3b8-46c7-bd71-035b286bf35c</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,6394fc3f-d3b8-46c7-bd71-035b286bf35c.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,6394fc3f-d3b8-46c7-bd71-035b286bf35c.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=6394fc3f-d3b8-46c7-bd71-035b286bf35c</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Someone on the project I am currently working on stumbled on some documentation for
WinCV, and in that documentation, it tells you how to add Assemblies which aren't
in the GAC. Here's the link from the MSDN, and then I will point out the interesting
part:
</p>
        <p>
          <a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpconwindowsformsclassviewerwincvexe.asp" target="_blank">http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpconwindowsformsclassviewerwincvexe.asp</a>
        </p>
        <p>
By using a <em>response file</em>, you can issue the necessary the parameters to look
at one or more files. From the documentation:
</p>
        <p>
          <font color="#0000ff">The following code shows the contents of a response file <code><code class="ce">myFile.rsp</code>. </code>Using
a response file eliminates the need to individually type the commands at the command
prompt.</font>
        </p>
        <pre class="code">
          <font color="#0000ff">/r:myAssembly.dll /r:myOtherAssembly.dll</font>
        </pre>
        <p>
          <font color="#0000ff">The following command reads the response file <code class="ce">myFile.rsp</code> and
executes the commands specified in the file.</font>
        </p>
        <pre class="code">
          <font color="#0000ff">wincv @myFile.rsp</font>
        </pre>
        <pre class="code">
          <font color="#000000">So,
you could set up a standard response file which holds all the names of assemblies
to search! </font>
        </pre>
        <pre class="code">Pretty neat!</pre>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=6394fc3f-d3b8-46c7-bd71-035b286bf35c" />
      </body>
      <title>WinCV revisited...</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,6394fc3f-d3b8-46c7-bd71-035b286bf35c.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/12/02/WinCVRevisited.aspx</link>
      <pubDate>Thu, 02 Dec 2004 05:42:28 GMT</pubDate>
      <description>&lt;p&gt;
Someone on the project I am currently working on stumbled on some documentation for
WinCV, and in that documentation, it tells you how to add Assemblies which aren't
in the GAC. Here's the link from the MSDN, and then I will point out the interesting
part:
&lt;/p&gt;
&lt;p&gt;
&lt;a href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpconwindowsformsclassviewerwincvexe.asp" target=_blank&gt;http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cptools/html/cpconwindowsformsclassviewerwincvexe.asp&lt;/a&gt;
&lt;/p&gt;
&lt;p&gt;
By using a &lt;em&gt;response file&lt;/em&gt;, you can issue the necessary the parameters to look
at one or more files. From the documentation:
&lt;/p&gt;
&lt;p&gt;
&lt;font color=#0000ff&gt;The following code shows the contents of a response file &lt;code&gt;&lt;code class=ce&gt;myFile.rsp&lt;/code&gt;. &lt;/code&gt;Using
a response file eliminates the need to individually type the commands at the command
prompt.&lt;/font&gt;
&lt;/p&gt;
&lt;pre class=code&gt;&lt;font color=#0000ff&gt;/r:myAssembly.dll /r:myOtherAssembly.dll&lt;/font&gt;&lt;/pre&gt;
&lt;p&gt;
&lt;font color=#0000ff&gt;The following command reads the response file &lt;code class=ce&gt;myFile.rsp&lt;/code&gt; and
executes the commands specified in the file.&lt;/font&gt;
&lt;/p&gt;
&lt;pre class=code&gt;&lt;font color=#0000ff&gt;wincv @myFile.rsp&lt;/font&gt;&lt;/pre&gt;&lt;pre class=code&gt;&lt;font color=#000000&gt;So,
you could set up a standard response file which holds all the names of assemblies
to search! &lt;/font&gt;&lt;/pre&gt;&lt;pre class=code&gt;Pretty neat!&lt;/pre&gt;&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=6394fc3f-d3b8-46c7-bd71-035b286bf35c" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,6394fc3f-d3b8-46c7-bd71-035b286bf35c.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>Tools</category>
      <category>VB.Net</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=6c55fa2b-a93d-4c46-bcbf-b45752c345ba</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,6c55fa2b-a93d-4c46-bcbf-b45752c345ba.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,6c55fa2b-a93d-4c46-bcbf-b45752c345ba.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=6c55fa2b-a93d-4c46-bcbf-b45752c345ba</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Here's another tip which is a wrapper to retrieve the value from an enum by it's text
and also to get the text of an enum based on a value.
</p>
        <p>
          <style type="text/css">
.csharpcode
{
 font-size: 10pt;
 color: black;
 font-family: Courier New , Courier, Monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0px; }
.rem { color: #008000; }
.kwrd { color: #0000ff; }
.str { color: #006080; }
.op { color: #0000c0; }
.preproc { color: #cc6633; }
.asp { background-color: #ffff00; }
.html { color: #800000; }
.attr { color: #ff0000; }
.alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0px;
}
.lnum { color: #606060; }
</style>
        </p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="kwrd">public</span>
            <span class="kwrd">static</span>
            <span class="kwrd">string</span> RetrieveEnumTextByValue
(Type enumType, Object value)</pre>
          <pre>{</pre>
          <pre class="alt">
            <span class="kwrd">if</span> (enumType.IsEnum)</pre>
          <pre>    {</pre>
          <pre class="alt">
            <span class="kwrd">if</span> (System.Enum.GetName(enumType,value)
!= <span class="kwrd">null</span>)</pre>
          <pre>
            <span class="kwrd">return</span> System.Enum.GetName(enumType,
value);</pre>
          <pre class="alt">    }</pre>
          <pre>
            <span class="kwrd">return</span>
            <span class="str">""</span>;</pre>
          <pre class="alt">}</pre>
          <pre>
          </pre>
          <pre class="alt">
            <span class="kwrd">public</span>
            <span class="kwrd">static</span>
            <span class="kwrd">int</span> RetrieveEnumValueByText(Type
enumType, <span class="kwrd">string</span> text)</pre>
          <pre>{</pre>
          <pre class="alt">
            <span class="kwrd">if</span> (enumType.IsEnum)</pre>
          <pre>    {</pre>
          <pre class="alt">
            <span class="kwrd">if</span> (System.Enum.Parse(enumType,text)
!= <span class="kwrd">null</span>)</pre>
          <pre>
            <span class="kwrd">return</span> Convert.ToInt32(System.Enum.Parse(enumType,
text));</pre>
          <pre class="alt">    }</pre>
          <pre>
            <span class="kwrd">return</span> -1;</pre>
          <pre class="alt">}</pre>
        </div>
        <p>
I'm a little lazy tonight, but maybe I will come in later and post usage. I'll make
a better effort to do that in the future, but I have to be up in a few hours, and
being tired tomorrow just won't do!
</p>
        <p>
-- Daryl
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=6c55fa2b-a93d-4c46-bcbf-b45752c345ba" />
      </body>
      <title>Tip of the Day: Retrieving an enum's value by text, and text by value</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,6c55fa2b-a93d-4c46-bcbf-b45752c345ba.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/11/30/TipOfTheDayRetrievingAnEnumsValueByTextAndTextByValue.aspx</link>
      <pubDate>Tue, 30 Nov 2004 05:11:10 GMT</pubDate>
      <description>&lt;p&gt;
Here's another tip which is a wrapper to retrieve the value from an enum by it's text
and also to get the text of an enum based on a value.
&lt;/p&gt;
&lt;p&gt;
&lt;style type=text/css&gt;
.csharpcode
{
 font-size: 10pt;
 color: black;
 font-family: Courier New , Courier, Monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0px; }
.rem { color: #008000; }
.kwrd { color: #0000ff; }
.str { color: #006080; }
.op { color: #0000c0; }
.preproc { color: #cc6633; }
.asp { background-color: #ffff00; }
.html { color: #800000; }
.attr { color: #ff0000; }
.alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0px;
}
.lnum { color: #606060; }
&lt;/style&gt;
&lt;div class=csharpcode&gt;&lt;pre class=alt&gt;&lt;span class=kwrd&gt;public&lt;/span&gt; &lt;span class=kwrd&gt;static&lt;/span&gt; &lt;span class=kwrd&gt;string&lt;/span&gt; RetrieveEnumTextByValue
(Type enumType, Object value)&lt;/pre&gt;&lt;pre&gt;{&lt;/pre&gt;&lt;pre class=alt&gt;    &lt;span class=kwrd&gt;if&lt;/span&gt; (enumType.IsEnum)&lt;/pre&gt;&lt;pre&gt;    {&lt;/pre&gt;&lt;pre class=alt&gt;        &lt;span class=kwrd&gt;if&lt;/span&gt; (System.Enum.GetName(enumType,value)
!= &lt;span class=kwrd&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre&gt;            &lt;span class=kwrd&gt;return&lt;/span&gt; System.Enum.GetName(enumType,
value);&lt;/pre&gt;&lt;pre class=alt&gt;    }&lt;/pre&gt;&lt;pre&gt;    &lt;span class=kwrd&gt;return&lt;/span&gt; &lt;span class=str&gt;""&lt;/span&gt;;&lt;/pre&gt;&lt;pre class=alt&gt;}&lt;/pre&gt;&lt;pre&gt;   &lt;/pre&gt;&lt;pre class=alt&gt;&lt;span class=kwrd&gt;public&lt;/span&gt; &lt;span class=kwrd&gt;static&lt;/span&gt; &lt;span class=kwrd&gt;int&lt;/span&gt; RetrieveEnumValueByText(Type
enumType, &lt;span class=kwrd&gt;string&lt;/span&gt; text)&lt;/pre&gt;&lt;pre&gt;{&lt;/pre&gt;&lt;pre class=alt&gt;    &lt;span class=kwrd&gt;if&lt;/span&gt; (enumType.IsEnum)&lt;/pre&gt;&lt;pre&gt;    {&lt;/pre&gt;&lt;pre class=alt&gt;        &lt;span class=kwrd&gt;if&lt;/span&gt; (System.Enum.Parse(enumType,text)
!= &lt;span class=kwrd&gt;null&lt;/span&gt;)&lt;/pre&gt;&lt;pre&gt;            &lt;span class=kwrd&gt;return&lt;/span&gt; Convert.ToInt32(System.Enum.Parse(enumType,
text));&lt;/pre&gt;&lt;pre class=alt&gt;    }&lt;/pre&gt;&lt;pre&gt;    &lt;span class=kwrd&gt;return&lt;/span&gt; -1;&lt;/pre&gt;&lt;pre class=alt&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
I'm a little lazy tonight, but maybe I will come in later and post usage. I'll make
a better effort to do that in the future, but I have to be up in a few hours, and
being tired tomorrow just won't do!
&lt;/p&gt;
&lt;p&gt;
-- Daryl
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=6c55fa2b-a93d-4c46-bcbf-b45752c345ba" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,6c55fa2b-a93d-4c46-bcbf-b45752c345ba.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=99c149c3-d442-4fef-b992-3406d3737e76</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,99c149c3-d442-4fef-b992-3406d3737e76.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,99c149c3-d442-4fef-b992-3406d3737e76.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=99c149c3-d442-4fef-b992-3406d3737e76</wfw:commentRss>
      <slash:comments>1</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Yet another tip of the day. I guess until I get an environment set up to go over my
Filter Component I will be posting a lot of tips just so I keep the blog active. Be
patient, it will be worth it when I get the project set up.
</p>
        <p>
CHAR() was a useful function for taking an integer value and returning the Ascii equivalent
from the value. There's a bit more to it in .Net, so here's a C# wrapper function
to do the same. Once again, there's no error handling or validation, so if this is
important to you (and it should be), caveat emptor.
</p>
        <p>
          <style type="text/css">
.csharpcode
{
 font-size: 10pt;
 color: black;
 font-family: Courier New , Courier, Monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0px; }
.rem { color: #008000; }
.kwrd { color: #0000ff; }
.str { color: #006080; }
.op { color: #0000c0; }
.preproc { color: #cc6633; }
.asp { background-color: #ffff00; }
.html { color: #800000; }
.attr { color: #ff0000; }
.alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0px;
}
.lnum { color: #606060; }
</style>
        </p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="kwrd">public</span>
            <span class="kwrd">static</span>
            <span class="kwrd">string</span> Char(<span class="kwrd">int</span> asciiCode)</pre>
          <pre>{</pre>
          <pre class="alt">    Byte[] charBytes = {asciiCode};</pre>
          <pre>
            <span class="kwrd">return</span> System.Text.Encoding.ASCII.GetString(charBytes);</pre>
          <pre class="alt">}</pre>
        </div>
        <div class="csharpcode"> 
</div>
        <div class="csharpcode">Enjoy!
</div>
        <p>
-- Daryl
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=99c149c3-d442-4fef-b992-3406d3737e76" />
      </body>
      <title>Tip of the Day: Simulating the CHAR function in C#</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,99c149c3-d442-4fef-b992-3406d3737e76.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/11/30/TipOfTheDaySimulatingTheCHARFunctionInC.aspx</link>
      <pubDate>Tue, 30 Nov 2004 05:05:16 GMT</pubDate>
      <description>&lt;p&gt;
Yet another tip of the day. I guess until I get an environment set up to go over my
Filter Component I will be posting a lot of tips just so I keep the blog active. Be
patient, it will be worth it when I get the project set up.
&lt;/p&gt;
&lt;p&gt;
CHAR() was a useful function for taking an integer value and returning the Ascii equivalent
from the value. There's a bit more to it in .Net, so here's a C# wrapper function
to do the same. Once again, there's no error handling or validation, so if this is
important to you (and it should be), caveat emptor.
&lt;/p&gt;
&lt;p&gt;
&lt;style type=text/css&gt;
.csharpcode
{
 font-size: 10pt;
 color: black;
 font-family: Courier New , Courier, Monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0px; }
.rem { color: #008000; }
.kwrd { color: #0000ff; }
.str { color: #006080; }
.op { color: #0000c0; }
.preproc { color: #cc6633; }
.asp { background-color: #ffff00; }
.html { color: #800000; }
.attr { color: #ff0000; }
.alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0px;
}
.lnum { color: #606060; }
&lt;/style&gt;
&lt;div class=csharpcode&gt;&lt;pre class=alt&gt;&lt;span class=kwrd&gt;public&lt;/span&gt; &lt;span class=kwrd&gt;static&lt;/span&gt; &lt;span class=kwrd&gt;string&lt;/span&gt; Char(&lt;span class=kwrd&gt;int&lt;/span&gt; asciiCode)&lt;/pre&gt;&lt;pre&gt;{&lt;/pre&gt;&lt;pre class=alt&gt;    Byte[] charBytes = {asciiCode};&lt;/pre&gt;&lt;pre&gt;    &lt;span class=kwrd&gt;return&lt;/span&gt; System.Text.Encoding.ASCII.GetString(charBytes);&lt;/pre&gt;&lt;pre class=alt&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;div class=csharpcode&gt;&amp;nbsp;
&lt;/div&gt;
&lt;div class=csharpcode&gt;Enjoy!
&lt;/div&gt;
&lt;p&gt;
-- Daryl
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=99c149c3-d442-4fef-b992-3406d3737e76" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,99c149c3-d442-4fef-b992-3406d3737e76.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=7b6b00b2-0581-45ef-b268-de0f649282c9</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,7b6b00b2-0581-45ef-b268-de0f649282c9.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,7b6b00b2-0581-45ef-b268-de0f649282c9.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=7b6b00b2-0581-45ef-b268-de0f649282c9</wfw:commentRss>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
This is a pretty simple tip (or set of tips) but one in which if you don't know, you're
going to be glad to find them out.
</p>
        <p>
First, depending on how your profile is set up in Visual Studio, you can type Ctrl-space
to get the Intellisense to come up. If there's only one possible option, it will go
ahead and type the rest out for you. For example, type “Sy” in the Code
behind editor, and press Ctrl-space. You should see a ton of “System”
options you can select from to complete the word.
</p>
        <p>
OK, that was easy, right? Well, here's a little one which is often overlooked: creating
an alias in your using statement.
</p>
        <p>
Typically, you might set up your “includes” as follows (in C#). 
</p>
        <p>
using System.XML;
</p>
        <p>
That works great if you are really familiar with the object model, and know what public
method/member you want. Suppose you don't? You can do this:
</p>
        <p>
using MyXML=System.XML;
</p>
        <p>
Now, when you type MyXML, you can get the full Intellisense for the System.XML without
having to type all that (or guess). Simple, but great for working with new workspaces.
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=7b6b00b2-0581-45ef-b268-de0f649282c9" />
      </body>
      <title>Tip of the Day: Speeding up your typing and Intellisense</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,7b6b00b2-0581-45ef-b268-de0f649282c9.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/11/29/TipOfTheDaySpeedingUpYourTypingAndIntellisense.aspx</link>
      <pubDate>Mon, 29 Nov 2004 16:36:57 GMT</pubDate>
      <description>&lt;p&gt;
This is a pretty simple tip (or set of tips) but one in which if you don't know, you're
going to be glad to find them out.
&lt;/p&gt;
&lt;p&gt;
First, depending on how your profile is set up in Visual Studio, you can type Ctrl-space
to get the Intellisense to come up. If there's only one possible option, it will go
ahead and type the rest out for you. For example, type &amp;#8220;Sy&amp;#8221; in the Code
behind editor, and press Ctrl-space. You should see a ton of &amp;#8220;System&amp;#8221;
options you can select from to complete the word.
&lt;/p&gt;
&lt;p&gt;
OK, that was easy, right? Well, here's a little one which is often overlooked: creating
an alias in your using statement.
&lt;/p&gt;
&lt;p&gt;
Typically, you might set up&amp;nbsp;your &amp;#8220;includes&amp;#8221; as follows (in C#). 
&lt;/p&gt;
&lt;p&gt;
using System.XML;
&lt;/p&gt;
&lt;p&gt;
That works great if you are really familiar with the object model, and know what public
method/member you want. Suppose you don't? You can do this:
&lt;/p&gt;
&lt;p&gt;
using MyXML=System.XML;
&lt;/p&gt;
&lt;p&gt;
Now, when you type MyXML, you can get the full Intellisense for the System.XML without
having to type all that (or guess). Simple, but great for working with new workspaces.
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=7b6b00b2-0581-45ef-b268-de0f649282c9" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,7b6b00b2-0581-45ef-b268-de0f649282c9.aspx</comments>
      <category>All Things</category>
      <category>C#</category>
      <category>Tips and Tricks</category>
    </item>
    <item>
      <trackback:ping>http://www.dotnettechnologies.com/Trackback.aspx?guid=67768dd0-2d77-4e2e-88d6-486d9ade4bc5</trackback:ping>
      <pingback:server>http://www.dotnettechnologies.com/pingback.aspx</pingback:server>
      <pingback:target>http://www.dotnettechnologies.com/PermaLink,guid,67768dd0-2d77-4e2e-88d6-486d9ade4bc5.aspx</pingback:target>
      <dc:creator />
      <wfw:comment>http://www.dotnettechnologies.com/CommentView,guid,67768dd0-2d77-4e2e-88d6-486d9ade4bc5.aspx</wfw:comment>
      <wfw:commentRss>http://www.dotnettechnologies.com/SyndicationService.asmx/GetEntryCommentsRss?guid=67768dd0-2d77-4e2e-88d6-486d9ade4bc5</wfw:commentRss>
      <slash:comments>2</slash:comments>
      <body xmlns="http://www.w3.org/1999/xhtml">
        <p>
Not sure where I got this, so my apologies to the original author, but it's been a
pretty useful function. Of course, you might want to wrap this with some error handling
and validation code, but here's a good start for you...
</p>
        <p>
          <style type="text/css">
.csharpcode
{
 font-size: 10pt;
 color: black;
 font-family: Courier New , Courier, Monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0px; }
.rem { color: #008000; }
.kwrd { color: #0000ff; }
.str { color: #006080; }
.op { color: #0000c0; }
.preproc { color: #cc6633; }
.asp { background-color: #ffff00; }
.html { color: #800000; }
.attr { color: #ff0000; }
.alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0px;
}
.lnum { color: #606060; }
</style>
        </p>
        <div class="csharpcode">
          <pre class="alt">
            <span class="kwrd">private</span>
            <span class="kwrd">string</span> GetRomanNumber(<span class="kwrd">int</span> number)</pre>
          <pre>{</pre>
          <pre class="alt">
            <span class="kwrd">string</span>[]
ArabicNums = <span class="kwrd">new</span><span class="kwrd">string</span>[] {<span class="str">"1"</span>, <span class="str">"4"</span>, <span class="str">"5"</span>, <span class="str">"9"</span>, <span class="str">"10"</span>, <span class="str">"40"</span>, <span class="str">"50"</span>, <span class="str">"90"</span>, <span class="str">"100"</span>, <span class="str">"400"</span>, <span class="str">"500"</span>, <span class="str">"900"</span>, <span class="str">"1000"</span>};</pre>
          <pre>
            <span class="kwrd">string</span>[]
RomanNums = <span class="kwrd">new</span><span class="kwrd">string</span>[] {<span class="str">"I"</span>,<span class="str">"IV"</span>,<span class="str">"V"</span>,<span class="str">"IX"</span>,<span class="str">"X"</span>,<span class="str">"XL"</span>,<span class="str">"L"</span>,<span class="str">"XC"</span>,<span class="str">"C"</span>,<span class="str">"CD"</span>,<span class="str">"D"</span>,<span class="str">"CM"</span>,<span class="str">"M"</span>};</pre>
          <pre class="alt"> </pre>
          <pre>
            <span class="kwrd">int</span> ArabicUpper
= ArabicNums.GetUpperBound(0);</pre>
          <pre class="alt">
            <span class="kwrd">int</span> ArabicLower
= ArabicNums.GetLowerBound(0);</pre>
          <pre> </pre>
          <pre class="alt">
            <span class="kwrd">string</span> Output
= <span class="str">""</span>;</pre>
          <pre> </pre>
          <pre class="alt">
            <span class="kwrd">for</span> (<span class="kwrd">int</span> i
= ArabicUpper; i &gt;= ArabicLower; i--)</pre>
          <pre>    {</pre>
          <pre class="alt">
            <span class="kwrd">while</span> (number
&gt;= Convert.ToInt32(ArabicNums[i]))</pre>
          <pre>        {</pre>
          <pre class="alt">            number -= Convert.ToInt32(ArabicNums[i]);</pre>
          <pre>            Output += RomanNums[i];</pre>
          <pre class="alt">        }</pre>
          <pre>    }</pre>
          <pre class="alt"> </pre>
          <pre>
            <span class="kwrd">return</span> Output;</pre>
          <pre class="alt">}</pre>
        </div>
        <p>
Enjoy!
</p>
        <img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=67768dd0-2d77-4e2e-88d6-486d9ade4bc5" />
      </body>
      <title>Tip of the Day: Converting an integer to a Roman Numeral in C#</title>
      <guid isPermaLink="false">http://www.dotnettechnologies.com/PermaLink,guid,67768dd0-2d77-4e2e-88d6-486d9ade4bc5.aspx</guid>
      <link>http://www.dotnettechnologies.com/2004/11/27/TipOfTheDayConvertingAnIntegerToARomanNumeralInC.aspx</link>
      <pubDate>Sat, 27 Nov 2004 04:25:01 GMT</pubDate>
      <description>&lt;p&gt;
Not sure where I got this, so my apologies to the original author, but it's been a
pretty useful function. Of course, you might want to wrap this with some error handling
and validation code, but here's a good start for you...
&lt;/p&gt;
&lt;p&gt;
&lt;style type=text/css&gt;
.csharpcode
{
 font-size: 10pt;
 color: black;
 font-family: Courier New , Courier, Monospace;
 background-color: #ffffff;
 /*white-space: pre;*/
}
.csharpcode pre { margin: 0px; }
.rem { color: #008000; }
.kwrd { color: #0000ff; }
.str { color: #006080; }
.op { color: #0000c0; }
.preproc { color: #cc6633; }
.asp { background-color: #ffff00; }
.html { color: #800000; }
.attr { color: #ff0000; }
.alt 
{
 background-color: #f4f4f4;
 width: 100%;
 margin: 0px;
}
.lnum { color: #606060; }
&lt;/style&gt;
&lt;div class=csharpcode&gt;&lt;pre class=alt&gt;&lt;span class=kwrd&gt;private&lt;/span&gt; &lt;span class=kwrd&gt;string&lt;/span&gt; GetRomanNumber(&lt;span class=kwrd&gt;int&lt;/span&gt; number)&lt;/pre&gt;&lt;pre&gt;{&lt;/pre&gt;&lt;pre class=alt&gt;    &lt;span class=kwrd&gt;string&lt;/span&gt;[]
ArabicNums = &lt;span class=kwrd&gt;new&lt;/span&gt; &lt;span class=kwrd&gt;string&lt;/span&gt;[] {&lt;span class=str&gt;"1"&lt;/span&gt;, &lt;span class=str&gt;"4"&lt;/span&gt;, &lt;span class=str&gt;"5"&lt;/span&gt;, &lt;span class=str&gt;"9"&lt;/span&gt;, &lt;span class=str&gt;"10"&lt;/span&gt;, &lt;span class=str&gt;"40"&lt;/span&gt;, &lt;span class=str&gt;"50"&lt;/span&gt;, &lt;span class=str&gt;"90"&lt;/span&gt;, &lt;span class=str&gt;"100"&lt;/span&gt;, &lt;span class=str&gt;"400"&lt;/span&gt;, &lt;span class=str&gt;"500"&lt;/span&gt;, &lt;span class=str&gt;"900"&lt;/span&gt;, &lt;span class=str&gt;"1000"&lt;/span&gt;};&lt;/pre&gt;&lt;pre&gt;    &lt;span class=kwrd&gt;string&lt;/span&gt;[]
RomanNums = &lt;span class=kwrd&gt;new&lt;/span&gt; &lt;span class=kwrd&gt;string&lt;/span&gt;[] {&lt;span class=str&gt;"I"&lt;/span&gt;,&lt;span class=str&gt;"IV"&lt;/span&gt;,&lt;span class=str&gt;"V"&lt;/span&gt;,&lt;span class=str&gt;"IX"&lt;/span&gt;,&lt;span class=str&gt;"X"&lt;/span&gt;,&lt;span class=str&gt;"XL"&lt;/span&gt;,&lt;span class=str&gt;"L"&lt;/span&gt;,&lt;span class=str&gt;"XC"&lt;/span&gt;,&lt;span class=str&gt;"C"&lt;/span&gt;,&lt;span class=str&gt;"CD"&lt;/span&gt;,&lt;span class=str&gt;"D"&lt;/span&gt;,&lt;span class=str&gt;"CM"&lt;/span&gt;,&lt;span class=str&gt;"M"&lt;/span&gt;};&lt;/pre&gt;&lt;pre class=alt&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;    &lt;span class=kwrd&gt;int&lt;/span&gt; ArabicUpper
= ArabicNums.GetUpperBound(0);&lt;/pre&gt;&lt;pre class=alt&gt;    &lt;span class=kwrd&gt;int&lt;/span&gt; ArabicLower
= ArabicNums.GetLowerBound(0);&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class=alt&gt;    &lt;span class=kwrd&gt;string&lt;/span&gt; Output
= &lt;span class=str&gt;""&lt;/span&gt;;&lt;/pre&gt;&lt;pre&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre class=alt&gt;    &lt;span class=kwrd&gt;for&lt;/span&gt; (&lt;span class=kwrd&gt;int&lt;/span&gt; i
= ArabicUpper; i &amp;gt;= ArabicLower; i--)&lt;/pre&gt;&lt;pre&gt;    {&lt;/pre&gt;&lt;pre class=alt&gt;        &lt;span class=kwrd&gt;while&lt;/span&gt; (number
&amp;gt;= Convert.ToInt32(ArabicNums[i]))&lt;/pre&gt;&lt;pre&gt;        {&lt;/pre&gt;&lt;pre class=alt&gt;            number -= Convert.ToInt32(ArabicNums[i]);&lt;/pre&gt;&lt;pre&gt;            Output += RomanNums[i];&lt;/pre&gt;&lt;pre class=alt&gt;        }&lt;/pre&gt;&lt;pre&gt;    }&lt;/pre&gt;&lt;pre class=alt&gt;&amp;nbsp;&lt;/pre&gt;&lt;pre&gt;    &lt;span class=kwrd&gt;return&lt;/span&gt; Output;&lt;/pre&gt;&lt;pre class=alt&gt;}&lt;/pre&gt;
&lt;/div&gt;
&lt;p&gt;
Enjoy!
&lt;/p&gt;
&lt;img width="0" height="0" src="http://www.dotnettechnologies.com/aggbug.ashx?id=67768dd0-2d77-4e2e-88d6-486d9ade4bc5" /&gt;</description>
      <comments>http://www.dotnettechnologies.com/CommentView,guid,67768dd0-2d77-4e2e-88d6-486d9ade4bc5.aspx</comments>
      <category>All Things</category>
      <category>ASP.Net</category>
      <category>General</category>
      <category>Tips and Tricks</category>
      <category>C#</category>
      <category>VB.Net</category>
    </item>
  </channel>
</rss>