<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Justin Stolle &#187; Programming</title>
	<atom:link href="http://blog.justinstolle.com/?feed=rss2&#038;cat=8" rel="self" type="application/rss+xml" />
	<link>http://blog.justinstolle.com</link>
	<description>Programming, Life, and Humor</description>
	<lastBuildDate>Thu, 19 Aug 2010 08:41:25 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>SQL: Turn a Date Range into a List of Dates</title>
		<link>http://blog.justinstolle.com/?p=128</link>
		<comments>http://blog.justinstolle.com/?p=128#comments</comments>
		<pubDate>Wed, 26 May 2010 01:14:24 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[cte]]></category>
		<category><![CDATA[recursive]]></category>
		<category><![CDATA[sql]]></category>

		<guid isPermaLink="false">http://blog.justinstolle.com/?p=128</guid>
		<description><![CDATA[I&#8217;m working on a project today that deals with date ranges being stored in SQL Server. Imagine a row in a table with a starting and an ending date. My desired output is to transform each single row into several, one for each date within the given date range. Since I couldn&#8217;t find an example [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m working on a project today that deals with date ranges being stored in SQL Server. Imagine a row in a table with a starting and an ending date. My desired output is to transform each single row into several, one for each date within the given date range.<br />
<span id="more-128"></span><br />
Since I couldn&#8217;t find an example exactly like what I needed, I felt I should share what I came up with. I&#8217;ll let the code speak for itself. It uses a recursive Common Table Expression (CTE).</p>
<p>The caveats are: you have to run this on <strong>SQL Server 2005</strong> or newer to use the <code>WITH</code> keyword, and if any individual date range is <strong>more than 100</strong> days, you&#8217;ll get an error by default [you can use <code>OPTION (MAXRECURSION value)</code> to increase that limit]. <strong>UPDATE:</strong> I&#8217;ve added a <code>WHERE</code> clause to prevent the error related to the default recursion limit. This change will leave out date ranges larger than 100 days, which is fine for me because anything larger than two weeks would be a data entry error in my situation.</p>
<pre class="brush: sql;">DECLARE @dateranges TABLE (range_id VARCHAR(2), date_begin DATETIME, date_end DATETIME)
INSERT @dateranges SELECT 'A', '2010-01-01', '2010-01-03'
INSERT @dateranges SELECT 'B', '2008-02-27', '2008-03-01'
INSERT @dateranges SELECT 'C', '2010-04-26', '2010-04-26'
INSERT @dateranges SELECT 'D', '2000-02-01', '2003-02-20'

;WITH cte (id, d)
     AS (SELECT tbl.range_id AS id
                ,tbl.date_begin AS d
           FROM @dateranges tbl
          WHERE DATEDIFF(DAY, tbl.date_begin, tbl.date_end) &lt;= 100
         UNION ALL
         SELECT tbl.range_id AS id
                ,DATEADD(DAY, 1, cte.d) AS d
           FROM cte
                INNER JOIN @dateranges tbl
                  ON cte.id = tbl.range_id
          WHERE cte.d &lt; tbl.date_end)
SELECT id AS range_id
       ,d AS date_within_range
  FROM cte
 ORDER BY id, d</pre>
<p>You start with this:</p>
<table>
<tbody>
<tr>
<th>range_id</th>
<th>date_begin</th>
<th>date_end</th>
</tr>
<tr>
<td>A</td>
<td>2010-01-01</td>
<td>2010-01-03</td>
</tr>
<tr>
<td>B</td>
<td>2008-02-27</td>
<td>2008-03-01</td>
</tr>
<tr>
<td>C</td>
<td>2010-04-26</td>
<td>2010-04-26</td>
</tr>
<tr>
<td>D</td>
<td>2000-02-01</td>
<td>2003-02-20</td>
</tr>
</tbody>
</table>
<p>and end up with this:</p>
<table>
<tbody>
<tr>
<th>range_id</th>
<th>date_within_range</th>
</tr>
<tr>
<td>A</td>
<td>2010-01-01</td>
</tr>
<tr>
<td>A</td>
<td>2010-01-02</td>
</tr>
<tr>
<td>A</td>
<td>2010-01-03</td>
</tr>
<tr>
<td>B</td>
<td>2008-02-27</td>
</tr>
<tr>
<td>B</td>
<td>2008-02-28</td>
</tr>
<tr>
<td>B</td>
<td>2008-02-29</td>
</tr>
<tr>
<td>B</td>
<td>2008-03-01</td>
</tr>
<tr>
<td>C</td>
<td>2010-04-26</td>
</tr>
</tbody>
</table>
<p>Notice that &#8220;D&#8221; is filtered out of these results.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.justinstolle.com/?feed=rss2&amp;p=128</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>WebControl with embedded stylesheet rendering at design time</title>
		<link>http://blog.justinstolle.com/?p=35</link>
		<comments>http://blog.justinstolle.com/?p=35#comments</comments>
		<pubDate>Fri, 20 Feb 2009 09:06:43 +0000</pubDate>
		<dc:creator>Justin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://justinstolle.com/blog/?p=35</guid>
		<description><![CDATA[I have a working solution to the embedded image in an embedded stylesheet problem, but I would appreciate any suggestions for improvement. This does its own substitution of the CSS file in the Designer class for the IDE. Transparency in PNGs don&#8217;t work so far, however. I&#8217;ll post some of the code here, but a [...]]]></description>
			<content:encoded><![CDATA[<p style="font-size: 11px;">I have a working solution to the embedded image in an embedded stylesheet problem, but I would appreciate any suggestions for improvement. This does its own substitution of the CSS file in the Designer class for the IDE. Transparency in PNGs don&#8217;t work so far, however. I&#8217;ll post some of the code here, but <a style="color: #034efa;" title="GizmonicInstitute.WebControls.zip" href="http://paragondesigns.com/code/GizmonicInstitute.WebControls.zip">a full example solution is available for download</a>.  I&#8217;d love to hear comments on this.  Thank you!<span id="more-35"></span></p>
<p style="font-size: 11px;"><strong>AssemblyInfo.cs (partial) </strong></p>
<pre style="font-size: small ! important;"><span style="color: #00d502;">// Styles</span>
[assembly: WebResource(<span style="color: #ff0000;">"GizmonicInstitute.WebControls.SampleControl.css"</span>, <span style="color: #ff0000;">"text/css"</span>, PerformSubstitution = <span style="color: #0000ff;">true</span>)]

<span style="color: #00d502;">// Images</span>
[assembly: WebResource(<span style="color: #ff0000;">"GizmonicInstitute.WebControls.cog.png"</span>, <span style="color: #ff0000;">"image/png"</span>)]
[assembly: WebResource(<span style="color: #ff0000;">"GizmonicInstitute.WebControls.inner_shadow.png"</span>, <span style="color: #ff0000;">"image/png"</span>)]</pre>
<p style="font-size: 11px;"><strong>SampleControl.css </strong></p>
<pre style="font-size: small ! important;">.<span style="color: #800000;">SampleControl_TextBox</span> {
 padding:<span style="color: #0000ff;"> <span style="color: #800000;">4</span>px <span style="color: #800000;">0 0 4</span>px</span>;
 height:<span style="color: #0000ff;"> <span style="color: #800000;">1.5</span>em</span>;
 border:<span style="color: #0000ff;"> solid <span style="color: #800000;">1</span>px Black</span>;
 background-color:<span style="color: #0000ff;"> Yellow</span>;
 background-image:<span style="color: #0000ff;"> url('&lt;%=WebResource("<span style="color: #ff0000;">GizmonicInstitute.WebControls.inner_shadow.png</span>")%&gt;')</span>;
 background-repeat:<span style="color: #0000ff;"> no-repeat</span>;
 background-position:<span style="color: #0000ff;"> left top</span>;
}

.<span style="color: #800000;">SampleControl_Button</span> {
 width:<span style="color: #0000ff;"> <span style="color: #800000;">2</span>em</span>;
 height:<span style="color: #0000ff;"> <span style="color: #800000;">2</span>em</span>;
 border-width:<span style="color: #0000ff;"> <span style="color: #800000;">2</span>px</span>;
 background-color:<span style="color: #0000ff;"> #<span style="color: #800000;">EAEAEA</span></span>;
 background-image:<span style="color: #0000ff;"> url('&lt;%=WebResource("<span style="color: #ff0000;">GizmonicInstitute.WebControls.cog.png</span>")%&gt;')</span>;
 background-repeat:<span style="color: #0000ff;"> no-repeat</span>;
 background-position:<span style="color: #0000ff;"> center center</span>;
}</pre>
<p><strong>SampleControl.cs </strong></p>
<pre style="font-size: small ! important;"><strong id="1" style="font-weight: normal; color: #008080;">1    </strong><span style="color: #0000ff;">#region</span><span style="color: #666666;"> Using directives</span>
<strong id="2" style="font-weight: normal; color: #008080;">2    </strong><span style="color: #0000ff;">using</span> System;
<strong id="3" style="font-weight: normal; color: #008080;">3    </strong><span style="color: #0000ff;">using</span> System.Collections.Generic;
<strong id="4" style="font-weight: normal; color: #008080;">4    </strong><span style="color: #0000ff;">using</span> System.ComponentModel;
<strong id="5" style="font-weight: normal; color: #008080;">5    </strong><span style="color: #0000ff;">using</span> System.Text;
<strong id="6" style="font-weight: normal; color: #008080;">6    </strong><span style="color: #0000ff;">using</span> System.Web;
<strong id="7" style="font-weight: normal; color: #008080;">7    </strong><span style="color: #0000ff;">using</span> System.Web.UI;
<strong id="8" style="font-weight: normal; color: #008080;">8    </strong><span style="color: #0000ff;">using</span> System.Web.UI.HtmlControls;
<strong id="9" style="font-weight: normal; color: #008080;">9    </strong><span style="color: #0000ff;">using</span> System.Web.UI.WebControls;
<strong id="10" style="font-weight: normal; color: #008080;">10   </strong><span style="color: #0000ff;">#endregion
<strong id="11" style="font-weight: normal; color: #008080;">11   </strong>
<strong id="12" style="font-weight: normal; color: #008080;">12   </strong>namespace</span> GizmonicInstitute.WebControls {
<strong id="13" style="font-weight: normal; color: #008080;">13   </strong>
<strong id="14" style="font-weight: normal; color: #008080;">14   </strong>    [Designer(<span style="color: #0000ff;">typeof</span>(SampleControlDesigner))]
<strong id="15" style="font-weight: normal; color: #008080;">15   </strong>    [DefaultProperty(<span style="color: #ff0000;">"TextBoxText"</span>)]
<strong id="16" style="font-weight: normal; color: #008080;">16   </strong>    [ToolboxData(<span style="color: #ff0000;">"&lt;{0}:SampleControl runat=server&gt;<!--{0}:SampleControl-->"</span>)]
<strong id="17" style="font-weight: normal; color: #008080;">17   </strong>    <span style="color: #0000ff;">public class</span> SampleControl : CompositeControl {
<strong id="18" style="font-weight: normal; color: #008080;">18   </strong>
<strong id="19" style="font-weight: normal; color: #008080;">19   </strong>        <span style="color: #0000ff;">protected</span> Label lblSample;
<strong id="20" style="font-weight: normal; color: #008080;">20   </strong>        <span style="color: #0000ff;">protected</span> TextBox txtSample;
<strong id="21" style="font-weight: normal; color: #008080;">21   </strong>        <span style="color: #0000ff;">protected</span> Button btnSample;
<strong id="22" style="font-weight: normal; color: #008080;">22   </strong>
<strong id="23" style="font-weight: normal; color: #008080;">23   </strong>        [Bindable(<span style="color: #0000ff;">true</span>)]
<strong id="24" style="font-weight: normal; color: #008080;">24   </strong>        [Category(<span style="color: #ff0000;">"Appearance"</span>)]
<strong id="25" style="font-weight: normal; color: #008080;">25   </strong>        [DefaultValue(<span style="color: #ff0000;">""</span>)]
<strong id="26" style="font-weight: normal; color: #008080;">26   </strong>        [Description(<span style="color: #ff0000;">"Gets or sets the text caption displayed in the Button control."</span>)]
<strong id="27" style="font-weight: normal; color: #008080;">27   </strong>        <span style="color: #0000ff;">public string</span> LabelText {
<strong id="28" style="font-weight: normal; color: #008080;">28   </strong>            <span style="color: #0000ff;">get</span> {
<strong id="29" style="font-weight: normal; color: #008080;">29   </strong>                <span style="color: #0000ff;">object</span> o = ViewState[<span style="color: #ff0000;">"LabelText"</span>];
<strong id="30" style="font-weight: normal; color: #008080;">30   </strong>                <span style="color: #0000ff;">return</span> (o == <span style="color: #0000ff;">null</span>) ? String.Empty : (<span style="color: #0000ff;">string</span>)o;
<strong id="31" style="font-weight: normal; color: #008080;">31   </strong>            }
<strong id="32" style="font-weight: normal; color: #008080;">32   </strong>            <span style="color: #0000ff;">set</span> {
<strong id="33" style="font-weight: normal; color: #008080;">33   </strong>                ViewState[<span style="color: #ff0000;">"LabelText"</span>] = <span style="color: #0000ff;">value</span>;
<strong id="34" style="font-weight: normal; color: #008080;">34   </strong>                RecreateChildControls();
<strong id="35" style="font-weight: normal; color: #008080;">35   </strong>            }
<strong id="36" style="font-weight: normal; color: #008080;">36   </strong>        }
<strong id="37" style="font-weight: normal; color: #008080;">37   </strong>
<strong id="38" style="font-weight: normal; color: #008080;">38   </strong>        [Bindable(<span style="color: #0000ff;">true</span>)]
<strong id="39" style="font-weight: normal; color: #008080;">39   </strong>        [Category(<span style="color: #ff0000;">"Appearance"</span>)]
<strong id="40" style="font-weight: normal; color: #008080;">40   </strong>        [DefaultValue(<span style="color: #ff0000;">""</span>)]
<strong id="41" style="font-weight: normal; color: #008080;">41   </strong>        [Description(<span style="color: #ff0000;">"Gets or sets the text caption displayed in the Button control."</span>)]
<strong id="42" style="font-weight: normal; color: #008080;">42   </strong>        <span style="color: #0000ff;">public string</span> TextBoxText {
<strong id="43" style="font-weight: normal; color: #008080;">43   </strong>            <span style="color: #0000ff;">get</span> {
<strong id="44" style="font-weight: normal; color: #008080;">44   </strong>                <span style="color: #0000ff;">object</span> o = ViewState[<span style="color: #ff0000;">"TextBoxText"</span>];
<strong id="45" style="font-weight: normal; color: #008080;">45   </strong>                <span style="color: #0000ff;">return</span> (o == <span style="color: #0000ff;">null</span>) ? String.Empty : (<span style="color: #0000ff;">string</span>)o;
<strong id="46" style="font-weight: normal; color: #008080;">46   </strong>            }
<strong id="47" style="font-weight: normal; color: #008080;">47   </strong>            <span style="color: #0000ff;">set</span> {
<strong id="48" style="font-weight: normal; color: #008080;">48   </strong>                ViewState[<span style="color: #ff0000;">"TextBoxText"</span>] = <span style="color: #0000ff;">value</span>;
<strong id="49" style="font-weight: normal; color: #008080;">49   </strong>                RecreateChildControls();
<strong id="50" style="font-weight: normal; color: #008080;">50   </strong>            }
<strong id="51" style="font-weight: normal; color: #008080;">51   </strong>        }
<strong id="52" style="font-weight: normal; color: #008080;">52   </strong>
<strong id="53" style="font-weight: normal; color: #008080;">53   </strong>        [Bindable(<span style="color: #0000ff;">true</span>)]
<strong id="54" style="font-weight: normal; color: #008080;">54   </strong>        [Category(<span style="color: #ff0000;">"Appearance"</span>)]
<strong id="55" style="font-weight: normal; color: #008080;">55   </strong>        [DefaultValue(<span style="color: #ff0000;">""</span>)]
<strong id="56" style="font-weight: normal; color: #008080;">56   </strong>        [Description(<span style="color: #ff0000;">"Gets or sets the text caption displayed in the Button control."</span>)]
<strong id="57" style="font-weight: normal; color: #008080;">57   </strong>        <span style="color: #0000ff;">public string</span> ButtonText {
<strong id="58" style="font-weight: normal; color: #008080;">58   </strong>            <span style="color: #0000ff;">get</span> {
<strong id="59" style="font-weight: normal; color: #008080;">59   </strong>                <span style="color: #0000ff;">object</span> o = ViewState[<span style="color: #ff0000;">"ButtonText"</span>];
<strong id="60" style="font-weight: normal; color: #008080;">60   </strong>                <span style="color: #0000ff;">return</span> (o == <span style="color: #0000ff;">null</span>) ? String.Empty : (<span style="color: #0000ff;">string</span>)o;
<strong id="61" style="font-weight: normal; color: #008080;">61   </strong>            }
<strong id="62" style="font-weight: normal; color: #008080;">62   </strong>            <span style="color: #0000ff;">set</span> {
<strong id="63" style="font-weight: normal; color: #008080;">63   </strong>                ViewState[<span style="color: #ff0000;">"ButtonText"</span>] = <span style="color: #0000ff;">value</span>;
<strong id="64" style="font-weight: normal; color: #008080;">64   </strong>                RecreateChildControls();
<strong id="65" style="font-weight: normal; color: #008080;">65   </strong>            }
<strong id="66" style="font-weight: normal; color: #008080;">66   </strong>        }
<strong id="67" style="font-weight: normal; color: #008080;">67   </strong>
<strong id="68" style="font-weight: normal; color: #008080;">68   </strong>        <span style="color: #0000ff;">protected void</span> btnSample_Click(Object sender, EventArgs e) {
<strong id="69" style="font-weight: normal; color: #008080;">69   </strong>            txtSample.Text = String.Format(<span style="color: #ff0000;">"Clicked at {0:h:mm:ss tt}"</span>, DateTime.Now );
<strong id="70" style="font-weight: normal; color: #008080;">70   </strong>        }
<strong id="71" style="font-weight: normal; color: #008080;">71   </strong>
<strong id="72" style="font-weight: normal; color: #008080;">72   </strong>        <span style="color: #0000ff;">protected override void</span> CreateChildControls() {
<strong id="73" style="font-weight: normal; color: #008080;">73   </strong>            lblSample = <span style="color: #0000ff;">new</span> Label();
<strong id="74" style="font-weight: normal; color: #008080;">74   </strong>            txtSample = <span style="color: #0000ff;">new</span> TextBox();
<strong id="75" style="font-weight: normal; color: #008080;">75   </strong>            btnSample = <span style="color: #0000ff;">new</span> Button();
<strong id="76" style="font-weight: normal; color: #008080;">76   </strong>
<strong id="77" style="font-weight: normal; color: #008080;">77   </strong>            lblSample.Text = <span style="color: #0000ff;">this</span>.LabelText;
<strong id="78" style="font-weight: normal; color: #008080;">78   </strong>            txtSample.Text = <span style="color: #0000ff;">this</span>.TextBoxText;
<strong id="79" style="font-weight: normal; color: #008080;">79   </strong>            btnSample.Text = <span style="color: #0000ff;">this</span>.ButtonText;
<strong id="80" style="font-weight: normal; color: #008080;">80   </strong>
<strong id="81" style="font-weight: normal; color: #008080;">81   </strong>            txtSample.CssClass = <span style="color: #ff0000;">"SampleControl_TextBox"</span>;
<strong id="82" style="font-weight: normal; color: #008080;">82   </strong>            btnSample.CssClass = <span style="color: #ff0000;">"SampleControl_Button"</span>;
<strong id="83" style="font-weight: normal; color: #008080;">83   </strong>            btnSample.Click += <span style="color: #0000ff;">new</span> EventHandler(btnSample_Click);
<strong id="84" style="font-weight: normal; color: #008080;">84   </strong>
<strong id="85" style="font-weight: normal; color: #008080;">85   </strong>            Controls.Add(lblSample);
<strong id="86" style="font-weight: normal; color: #008080;">86   </strong>            Controls.Add(txtSample);
<strong id="87" style="font-weight: normal; color: #008080;">87   </strong>            Controls.Add(btnSample);
<strong id="88" style="font-weight: normal; color: #008080;">88   </strong>        }
<strong id="89" style="font-weight: normal; color: #008080;">89   </strong>
<strong id="90" style="font-weight: normal; color: #008080;">90   </strong>        <span style="color: #0000ff;">protected override void</span> OnPreRender(EventArgs e) {
<strong id="91" style="font-weight: normal; color: #008080;">91   </strong>            <span style="color: #00d502;">// Add embedded style sheet to parent page</span>
<strong id="92" style="font-weight: normal; color: #008080;">92   </strong>            HtmlLink cssLink = <span style="color: #0000ff;">new</span> HtmlLink();
<strong id="93" style="font-weight: normal; color: #008080;">93   </strong>            cssLink.ID = <span style="color: #ff0000;">"SampleControlCss"</span>;
<strong id="94" style="font-weight: normal; color: #008080;">94   </strong>            cssLink.Href = Page.ClientScript.GetWebResourceUrl(<span style="color: #0000ff;">this</span>.GetType(), <span style="color: #ff0000;">"GizmonicInstitute.WebControls.SampleControl.css"</span>);
<strong id="95" style="font-weight: normal; color: #008080;">95   </strong>            cssLink.Attributes.Add(<span style="color: #ff0000;">"rel"</span>, <span style="color: #ff0000;">"stylesheet"</span>);
<strong id="96" style="font-weight: normal; color: #008080;">96   </strong>            cssLink.Attributes.Add(<span style="color: #ff0000;">"type"</span>, <span style="color: #ff0000;">"text/css"</span>);
<strong id="97" style="font-weight: normal; color: #008080;">97   </strong>            <span style="color: #0000ff;">bool</span> CssLinkAlreadyExists = <span style="color: #0000ff;">false</span>;
<strong id="98" style="font-weight: normal; color: #008080;">98   </strong>            <span style="color: #0000ff;">foreach</span> (Control headctrl <span style="color: #0000ff;">in</span> Page.Header.Controls) {
<strong id="99" style="font-weight: normal; color: #008080;">99   </strong>                <span style="color: #0000ff;">if</span> (headctrl.ID == cssLink.ID) {
<strong id="100" style="font-weight: normal; color: #008080;">100  </strong>                    CssLinkAlreadyExists = <span style="color: #0000ff;">true</span>;
<strong id="101" style="font-weight: normal; color: #008080;">101  </strong>                    <span style="color: #0000ff;">break</span>;
<strong id="102" style="font-weight: normal; color: #008080;">102  </strong>                }
<strong id="103" style="font-weight: normal; color: #008080;">103  </strong>            }
<strong id="104" style="font-weight: normal; color: #008080;">104  </strong>            <span style="color: #0000ff;">if</span> (!CssLinkAlreadyExists) {
<strong id="105" style="font-weight: normal; color: #008080;">105  </strong>                Page.Header.Controls.AddAt(0, cssLink);
<strong id="106" style="font-weight: normal; color: #008080;">106  </strong>            }
<strong id="107" style="font-weight: normal; color: #008080;">107  </strong>        }
<strong id="108" style="font-weight: normal; color: #008080;">108  </strong>
<strong id="109" style="font-weight: normal; color: #008080;">109  </strong>    }
<strong id="110" style="font-weight: normal; color: #008080;">110  </strong>}</pre>
<p><strong>SampleControlDesigner.cs</strong></p>
<pre style="font-size: small ! important;"><strong id="1" style="font-weight: normal; color: #008080;">1    </strong><span style="color: #0000ff;">#region</span><span style="color: #666666;"> Using directives</span>
<strong id="2" style="font-weight: normal; color: #008080;">2    </strong><span style="color: #0000ff;">using</span> System;
<strong id="3" style="font-weight: normal; color: #008080;">3    </strong><span style="color: #0000ff;">using</span> System.Web.UI;
<strong id="4" style="font-weight: normal; color: #008080;">4    </strong><span style="color: #0000ff;">using</span> System.Text.RegularExpressions;
<strong id="5" style="font-weight: normal; color: #008080;">5    </strong><span style="color: #0000ff;">#endregion
<strong id="6" style="font-weight: normal; color: #008080;">6    </strong>
<strong id="7" style="font-weight: normal; color: #008080;">7    </strong>namespace</span> GizmonicInstitute.WebControls {
<strong id="8" style="font-weight: normal; color: #008080;">8    </strong>
<strong id="9" style="font-weight: normal; color: #008080;">9    </strong>    <span style="color: #0000ff;">public class</span> SampleControlDesigner : System.Web.UI.Design.ControlDesigner {
<strong id="10" style="font-weight: normal; color: #008080;">10   </strong>        <span style="color: #0000ff;">public override string</span> GetDesignTimeHtml() {
<strong id="11" style="font-weight: normal; color: #008080;">11   </strong>            System.Reflection.Assembly l_asm = System.Reflection.Assembly.GetExecutingAssembly();
<strong id="12" style="font-weight: normal; color: #008080;">12   </strong>            System.IO.Stream l_css_res = l_asm.GetManifestResourceStream(<span style="color: #ff0000;">"GizmonicInstitute.WebControls.SampleControl.css"</span>);
<strong id="13" style="font-weight: normal; color: #008080;">13   </strong>            System.IO.StreamReader l_stream = <span style="color: #0000ff;">new</span> System.IO.StreamReader(l_css_res);
<strong id="14" style="font-weight: normal; color: #008080;">14   </strong>            <span style="color: #0000ff;">string</span> ls_css = l_stream.ReadToEnd();
<strong id="15" style="font-weight: normal; color: #008080;">15   </strong>
<strong id="16" style="font-weight: normal; color: #008080;">16   </strong>            <span style="color: #0000ff;">const string</span> SUBSTITUTION_PATTERN = @<span style="color: #ff0000;">"(&lt;%=)\s*(WebResource\("")(?.+)\s*(""\)%&gt;)"</span>;
<strong id="17" style="font-weight: normal; color: #008080;">17   </strong>            Regex theRegex = <span style="color: #0000ff;">new</span> Regex(SUBSTITUTION_PATTERN);
<strong id="18" style="font-weight: normal; color: #008080;">18   </strong>            ls_css = theRegex.Replace(ls_css, <span style="color: #0000ff;">new</span> MatchEvaluator(PerformSubstitution));
<strong id="19" style="font-weight: normal; color: #008080;">19   </strong>
<strong id="20" style="font-weight: normal; color: #008080;">20   </strong>            <span style="color: #0000ff;">return</span> <span style="color: #ff0000;">"<!--
"</span> + ls_css + <span style="color: rgb(255, 0, 0); " mce_style="color: #ff0000; ">"
-->"</span> + <span style="color: #0000ff;">base</span>.GetDesignTimeHtml();
<strong id="21" style="font-weight: normal; color: #008080;">21   </strong>        }
<strong id="22" style="font-weight: normal; color: #008080;">22   </strong>
<strong id="23" style="font-weight: normal; color: #008080;">23   </strong>        <span style="color: #0000ff;">private string</span> PerformSubstitution(Match m) {
<strong id="24" style="font-weight: normal; color: #008080;">24   </strong>            SampleControl thisWeightControl = (SampleControl)Component;
<strong id="25" style="font-weight: normal; color: #008080;">25   </strong>            <span style="color: #0000ff;">string</span> replacedString = m.ToString();
<strong id="26" style="font-weight: normal; color: #008080;">26   </strong>            replacedString = replacedString.Replace(m.Value, thisWeightControl.Page.ClientScript.GetWebResourceUrl(<span style="color: #0000ff;">this</span>.GetType(), m.Groups[<span style="color: #ff0000;">"resourceName"</span>].Value));
<strong id="27" style="font-weight: normal; color: #008080;">27   </strong>            <span style="color: #0000ff;">return</span> replacedString;
<strong id="28" style="font-weight: normal; color: #008080;">28   </strong>        }
<strong id="29" style="font-weight: normal; color: #008080;">29   </strong>    }
<strong id="30" style="font-weight: normal; color: #008080;">30   </strong>
<strong id="31" style="font-weight: normal; color: #008080;">31   </strong>}</pre>
]]></content:encoded>
			<wfw:commentRss>http://blog.justinstolle.com/?feed=rss2&amp;p=35</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
