<?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>Sam Beauvois &#187; Tips and Tricks</title>
	<atom:link href="http://www.sambeauvois.be/blog/category/tips-and-tricks/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.sambeauvois.be/blog</link>
	<description>general dev, .net and other stuff</description>
	<lastBuildDate>Fri, 03 Sep 2010 14:11:38 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.6</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to set two background images for an HTML page ?</title>
		<link>http://www.sambeauvois.be/blog/2010/06/how-to-set-two-background-images-for-an-html-page/</link>
		<comments>http://www.sambeauvois.be/blog/2010/06/how-to-set-two-background-images-for-an-html-page/#comments</comments>
		<pubDate>Mon, 07 Jun 2010 07:50:26 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[CSS]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Web design]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[Images]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=414</guid>
		<description><![CDATA[The other day I was wondering how could I set two background images for an HTML page and I came with one solution.
I don&#8217;t know if it&#8217;s the best way to do that but it worked as I wanted.
To explain the solution, here is the complete steps I made
First I had an HTML page without [...]]]></description>
			<content:encoded><![CDATA[<p>The other day I was wondering how could I set two background images for an HTML page and I came with one solution.<br />
I don&#8217;t know if it&#8217;s the best way to do that but it worked as I wanted.</p>
<p>To explain the solution, here is the complete steps I made</p>
<p>First I had an HTML page without any background:</p>
<p style="text-align: center;"><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/Beach_withoutBackground1.jpg" target="_blank"><img class="aligncenter size-medium wp-image-420" title="Beach_withoutBackground" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/Beach_withoutBackground1-480x263.jpg" alt="Beach_withoutBackground" width="480" height="263" /></a></p>
<p>Then I added some CSS to set a background image :</p>
<p style="text-align: center;"><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/bg.gif" target="_blank"><img class="aligncenter size-medium wp-image-421" title="bg" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/bg-480x385.gif" alt="bg" width="480" height="385" /></a></p>
<pre class="brush: css;">
body
{
   background:url(&quot;img/bg.gif&quot;) no-repeat fixed left top #9AE4E8;
}
</pre>
<p style="text-align: left;">The result was good :<br />
<a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/Beach_OneBackground.jpg" target="_blank"><img class="aligncenter size-medium wp-image-422" title="Beach_OneBackground" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/Beach_OneBackground-480x266.jpg" alt="Beach_OneBackground" width="480" height="266" /></a><br />
But I wanted to add a second background image on the right bottom :<br />
<a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/logobeachrahier_medium.png" target="_blank"><img class="aligncenter size-medium wp-image-423" title="logobeachrahier_medium" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/logobeachrahier_medium-480x580.png" alt="logobeachrahier_medium" width="480" height="580" /></a><br />
So I moved my background declaration for the head part of the html file</p>
<pre class="brush: css;">
html
{
 background:url(&quot;img/bg.gif&quot;) no-repeat fixed left top #9AE4E8;
}
</pre>
<p>and I added an other background declaration for the body part</p>
<pre class="brush: css;">
body
{
 background:url(&quot;img/logobeachrahier_medium.png&quot;) no-repeat fixed right bottom ;
}
</pre>
<p>The background declared for the body is applied over the html one:</p>
<p style="text-align: left;"><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/Beach_TwoBackground.jpg" target="_blank"><img class="aligncenter size-medium wp-image-424" title="Beach_TwoBackground" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/06/Beach_TwoBackground-480x264.jpg" alt="Beach_TwoBackground" width="480" height="264" /></a><br />
I think it&#8217;s Pretty good now.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/06/how-to-set-two-background-images-for-an-html-page/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Change the Office 2010 product key</title>
		<link>http://www.sambeauvois.be/blog/2010/04/change-the-office-2010-product-key/</link>
		<comments>http://www.sambeauvois.be/blog/2010/04/change-the-office-2010-product-key/#comments</comments>
		<pubDate>Fri, 30 Apr 2010 12:39:02 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[Office]]></category>
		<category><![CDATA[Tips and Tricks]]></category>
		<category><![CDATA[Activation]]></category>
		<category><![CDATA[Product Key]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/2010/04/change-the-office-2010-product-key/</guid>
		<description><![CDATA[A few days ago I received Office 2010 from work.
I installed it with the provided product key, and tried to activate it:


Unfortunately, the product key has been already activated for the maximum number of times permitted.

So I asked for a new key, I received it and I tried to change the key

After several researches, I [...]]]></description>
			<content:encoded><![CDATA[<p>A few days ago I received Office 2010 from work.</p>
<p>I installed it with the provided product key, and tried to activate it:</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image17.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image_thumb17.png" border="0" alt="image" width="484" height="418" /></a></p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image31.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image31_thumb.png" border="0" alt="image" width="484" height="418" /></a></p>
<p>Unfortunately, the product key has been already activated for the maximum number of times permitted.</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image61.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image6_thumb.png" border="0" alt="image" width="484" height="418" /></a></p>
<p>So I asked for a new key, I received it and I tried to change the key</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image121.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image12_thumb.png" border="0" alt="image" width="484" height="388" /></a></p>
<p>After several researches, I couldn&#8217;t find an option to change this key.</p>
<p>I finally tried to repair the installation, so I start the office installer</p>
<p>and  the wanted option was here :</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image151.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image15_thumb.png" border="0" alt="image" width="484" height="395" /></a></p>
<p>Choose “Enter a product key” then click on Continue</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image18.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image18_thumb.png" border="0" alt="image" width="484" height="395" /></a></p>
<p>Enter your product key and click on &#8220;Continue&#8221;.</p>
<p>Then you cant choose if you want to install additional office options</p>
<p>Now it’s activated !</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image19.png" target="_blank"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://www.sambeauvois.be/blog/wp-content/uploads/2010/04/image1_thumb.png" border="0" alt="image" width="484" height="388" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/04/change-the-office-2010-product-key/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to change the style elements of a listview? (the simple way)</title>
		<link>http://www.sambeauvois.be/blog/2010/01/how-to-change-the-style-elements-of-a-listview-the-simple-way/</link>
		<comments>http://www.sambeauvois.be/blog/2010/01/how-to-change-the-style-elements-of-a-listview-the-simple-way/#comments</comments>
		<pubDate>Thu, 14 Jan 2010 13:14:40 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=141</guid>
		<description><![CDATA[With the ast.net listview control, you can set an AlternatingItemTemplate in order to change the display or what you want.
If you just want to change the backcolor or things like that, you can spare some time by using only the ItemTemplate and applying a diffenrent style depending of the index (use of the Container.DataItemIndex property).
example [...]]]></description>
			<content:encoded><![CDATA[<p>With the ast.net listview control, you can set an <em>AlternatingItemTemplate </em>in order to change the display or what you want.</p>
<p>If you just want to change the backcolor or things like that, you can spare some time by using only the <em>ItemTemplate </em>and applying a diffenrent style depending of the index (use of the <strong>Container.DataItemIndex</strong> property).</p>
<p><em>example</em> : let’s say that your listview generate a &lt;table&gt; and each <em>ItemTemplate</em> generate a row of this table, just do :</p>
<pre class="brush: xml;">
&lt;ItemTemplate&gt;
  &lt;tr class='&lt;%# Container.DataItemIndex % 2 == 0 ? “normal” : “alternating” %&gt;'&gt;
    &lt;td&gt;blah blah&lt;/td&gt;
  &lt;/tr&gt;
&lt;/ItemTemplate&gt;
</pre>
<p><span><span style="background-color: #ffffff" title="c'est tout">that&#8217;s all you need !<br />
</span></span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/01/how-to-change-the-style-elements-of-a-listview-the-simple-way/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How to use a ValidationSummary to display server errors?</title>
		<link>http://www.sambeauvois.be/blog/2010/01/asp-net-howto-use-a-validationsummary-to-display-server-errors/</link>
		<comments>http://www.sambeauvois.be/blog/2010/01/asp-net-howto-use-a-validationsummary-to-display-server-errors/#comments</comments>
		<pubDate>Wed, 13 Jan 2010 07:15:17 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=133</guid>
		<description><![CDATA[Imagine you want to use your ValidationSummary to display server errors as client error, there is a simple way to do that.
First, declare your ValidationSummary, and a CustomValidator with Display property set to &#8220;None&#8221;


&#60;asp:CustomValidator ID=&#34;ServerErrorCustomValidator&#34;
Display=&#34;None&#34; runat=&#34;server&#34; ValidationGroup=&#34;MyValidationGroup&#34; /&#62;

&#60;asp:ValidationSummary ID=&#34;AdministrationTaskValidationSummary&#34; runat=&#34;server&#34; ValidationGroup=&#34;MyValidationGroup&#34;/&#62;

Next, in your application code, when an error occurs : set the CustomValidator&#8217;s ErrorMessage and [...]]]></description>
			<content:encoded><![CDATA[<p>Imagine you want to use your ValidationSummary to display server errors as client error, there is a simple way to do that.</p>
<p>First, declare your <strong>ValidationSummary</strong>, and a <strong>CustomValidator </strong>with <strong>Display </strong>property set to <em><strong>&#8220;None&#8221;</strong></em></p>
<pre class="brush: xml;">

&lt;asp:CustomValidator ID=&quot;ServerErrorCustomValidator&quot;
Display=&quot;None&quot; runat=&quot;server&quot; ValidationGroup=&quot;MyValidationGroup&quot; /&gt;

&lt;asp:ValidationSummary ID=&quot;AdministrationTaskValidationSummary&quot; runat=&quot;server&quot; ValidationGroup=&quot;MyValidationGroup&quot;/&gt;
</pre>
<p>Next, in your application code, when an error occurs : set the CustomValidator&#8217;s <strong>ErrorMessage </strong>and <strong>IsValid </strong>properties :</p>
<pre class="brush: csharp;">

ServerErrorCustomValidator.ErrorMessage = &quot;Server error :  error description&quot;;
ServerErrorCustomValidator.IsValid = false;
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2010/01/asp-net-howto-use-a-validationsummary-to-display-server-errors/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>C#, check if a string is null or empty</title>
		<link>http://www.sambeauvois.be/blog/2009/12/c-check-if-a-string-is-null-or-empty/</link>
		<comments>http://www.sambeauvois.be/blog/2009/12/c-check-if-a-string-is-null-or-empty/#comments</comments>
		<pubDate>Mon, 07 Dec 2009 22:08:21 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=120</guid>
		<description><![CDATA[In C# you can check if a string is null or empty in many ways :

string String1 = &#34;testString&#34;;
if (String1== null &#124;&#124; String1 == &#34;&#34;)
{
// ...
}
else
{
// ...
}



string String1 = &#34;testString&#34;;
 if (String1 == null &#124;&#124; String1.Length==0)
 {
 // ...
 }
 else
 {
 // ...
 }


 string String1 = &#34;testString&#34;;
 if (string.IsNullOrEmpty(String1))
 {
 // ...
 }
 [...]]]></description>
			<content:encoded><![CDATA[<p>In C# you can check if a string is null or empty in many ways :</p>
<pre class="brush: csharp;">
string String1 = &quot;testString&quot;;
if (String1== null || String1 == &quot;&quot;)
{
// ...
}
else
{
// ...
}
</pre>
<pre class="brush: csharp;">

string String1 = &quot;testString&quot;;
 if (String1 == null || String1.Length==0)
 {
 // ...
 }
 else
 {
 // ...
 }
</pre>
<pre class="brush: csharp;">
 string String1 = &quot;testString&quot;;
 if (string.IsNullOrEmpty(String1))
 {
 // ...
 }
 else
 {
 // ...
 }
</pre>
<p>The last one is more readable.</p>
<p>But what about performances ?</p>
<p>Check this code :</p>
<pre class="brush: csharp;">
private void CheckForNullOrEmpty()
 {
 int maxIterations = 9999999;

 Console.WriteLine(&quot;if (string.IsNullOrEmpty(String1))&quot;);
 Stopwatch watch = Stopwatch.StartNew();
 for (int i = 0; i &lt; maxIterations; i++)
 {
 string String1 = &quot;testString&quot;;
 if (string.IsNullOrEmpty(String1))
 {
 // ...
 }
 else
 {
 // ...
 }
 }

 watch.Stop();
 Console.WriteLine(&quot;\tTime : &quot; + watch.Elapsed.TotalMilliseconds);
 Console.WriteLine(Environment.NewLine);

 Console.WriteLine(&quot;if (String1== null || String1 == \&quot;\&quot;&quot;);
 watch = Stopwatch.StartNew();
 for (int i = 0; i &lt; maxIterations; i++)
 {
 string String1 = &quot;testString&quot;;
 if (String1 == null || String1 == &quot;&quot;)
 {
 // ...
 }
 else
 {
 // ...
 }
 }

 watch.Stop();
 Console.WriteLine(&quot;\tTime : &quot; + watch.Elapsed.TotalMilliseconds);
 Console.WriteLine(Environment.NewLine);

 Console.WriteLine(&quot;if (String1 == null || String1.Length==0)&quot;);
 watch = Stopwatch.StartNew();
 for (int i = 0; i &lt; maxIterations; i++)
 {
 string String1 = &quot;testString&quot;;
 if (String1 == null || String1.Length == 0)
 {
 // ...
 }
 else
 {
 // ...
 }
 }

 watch.Stop();
 Console.WriteLine(&quot;\tTime : &quot; + watch.Elapsed.TotalMilliseconds);
 Console.WriteLine(Environment.NewLine);

 Console.WriteLine(Environment.NewLine);
 Console.WriteLine(&quot;Press any key to continue&quot;);
 Console.ReadLine();
 }
</pre>
<p>Output is :</p>
<p><a href="http://www.sambeauvois.be/blog/wp-content/uploads/2009/12/CheckStringForNullOrEmptyOutput.png"><img class="aligncenter size-full wp-image-122" src="http://www.sambeauvois.be/blog/wp-content/uploads/2009/12/CheckStringForNullOrEmptyOutput.png" alt="CheckStringForNullOrEmptyOutput" width="677" height="342" /></a></p>
<p>The difference between<strong> &#8220;String.IsNullOrEmpty&#8221;</strong> and <strong>&#8220;check for null then for lenght</strong>&#8221; is minimal, so prefer the String.IsNullOrEmpty() wich is more readable.</p>
<p>As you can guess, IsNullOrEmpty performs a check for null, then a check for lenght :</p>
<p>If you use Reflector to inspect the <a href="http://msdn.microsoft.com/en-us/library/system.string.aspx" target="_blank" onclick="pageTracker._trackPageview('/outgoing/msdn.microsoft.com/en-us/library/system.string.aspx?referer=');">String</a> class in the mscorlib, you can see that String.IsNullOrEmpty do the same thing we do in our test :</p>
<pre class="brush: csharp;">
public static bool IsNullOrEmpty(string value)
{
if (value != null)
{
return (value.Length == 0);
}
return true;
}
</pre>
<p>the &#8220;extra&#8221; time comes from the method call</pre>
<p>Note : In .Net Framework 4.0: string.IsNullOrWhiteSpace() method appears, but I've not tested yet (<a href="http://weblogs.asp.net/gunnarpeipman/archive/2009/10/25/net-framework-4-0-string-isnullorwhitespace-method.aspx" target="_blank" onclick="pageTracker._trackPageview('/outgoing/weblogs.asp.net/gunnarpeipman/archive/2009/10/25/net-framework-4-0-string-isnullorwhitespace-method.aspx?referer=');">link</a>)</p>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2009/12/c-check-if-a-string-is-null-or-empty/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>How long need a portion of code to be executed ?</title>
		<link>http://www.sambeauvois.be/blog/2009/12/how-long-need-a-portion-of-code-to-be-executed/</link>
		<comments>http://www.sambeauvois.be/blog/2009/12/how-long-need-a-portion-of-code-to-be-executed/#comments</comments>
		<pubDate>Fri, 04 Dec 2009 08:44:07 +0000</pubDate>
		<dc:creator>Sam Beauvois</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[Source Code]]></category>
		<category><![CDATA[Tips and Tricks]]></category>

		<guid isPermaLink="false">http://www.sambeauvois.be/blog/?p=106</guid>
		<description><![CDATA[Use the Stopwatch object !

using System.Diagnostics;

// ...

Stopwatch myStopWatch = Stopwatch.StartNew();

// some code

myStopWatch.Stop();

Console.WriteLine(&#34;{0} ms - {1} ticks&#34;, myStopWatch.Elapsed.TotalMilliseconds, myStopWatch.ElapsedTicks);

// ...

]]></description>
			<content:encoded><![CDATA[<p>Use the Stopwatch object !</p>
<pre class="brush: csharp;">
using System.Diagnostics;

// ...

Stopwatch myStopWatch = Stopwatch.StartNew();

// some code

myStopWatch.Stop();

Console.WriteLine(&quot;{0} ms - {1} ticks&quot;, myStopWatch.Elapsed.TotalMilliseconds, myStopWatch.ElapsedTicks);

// ...
</pre>
]]></content:encoded>
			<wfw:commentRss>http://www.sambeauvois.be/blog/2009/12/how-long-need-a-portion-of-code-to-be-executed/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>
