<?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>Frederik Vig - ASP.NET developer &#187; C#</title>
	<atom:link href="http://www.frederikvig.com/category/c/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.frederikvig.com</link>
	<description></description>
	<lastBuildDate>Wed, 28 Jul 2010 14:08:42 +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>EPiServer code walkthrough #1 &#8211; 404 handler</title>
		<link>http://www.frederikvig.com/2010/01/episerver-code-walkthrough-1-404-handler/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=episerver-code-walkthrough-1-404-handler</link>
		<comments>http://www.frederikvig.com/2010/01/episerver-code-walkthrough-1-404-handler/#comments</comments>
		<pubDate>Fri, 29 Jan 2010 15:10:11 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[EPiServer]]></category>
		<category><![CDATA[EPiServer code walkthrough]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=1038</guid>
		<description><![CDATA[This is the first post in a new series called &#8220;EPiServer code walkthrough&#8221;. What I&#8217;ll do is go through one new EPiServer module in each post. Writing a little about what it does, learn by reading its code, and hopefully contributing a little back to the project, if I see any bugs or harmful/unnecessary code [...]]]></description>
			<content:encoded><![CDATA[<p>This is the first post in a new series called &#8220;EPiServer code walkthrough&#8221;. What I&#8217;ll do is go through one new EPiServer module in each post. Writing a little about what it does, learn by reading its code, and  hopefully contributing a little back to the project, if I see any bugs or harmful/unnecessary code that is <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> . </p>
<p>I&#8217;m a firm believer that reading code helps you become a better developer. There are lots of modules even I just recently came across, that I didn&#8217;t know existed just a few weeks back. I think I&#8217;m not the only one, especially since they are spread around on various blogs, <a href="http://www.codeplex.com/">CodePlex</a>, <a href="https://www.coderesort.com/p/epicode/wiki/WikiStart">EPiCode</a> and other places. They all contain valuable code that we as EPiServer developers should read.</p>
<p>I&#8217;m starting with a module I personally have not used much before, but that I know a lot of people have used in their projects: the <a href="https://www.coderesort.com/p/epicode/wiki/404Handler">custom 404 handler</a>. </p>
<blockquote><p>
<cite>From the project wiki page</cite></p>
<p>This module has a more advanced url redirect feature than the built-in shortcut url feature in EPiServer. It handles extensions and querystring parameters too. If you have a lot of 404 errors in your logs, you can use this to redirect the user to the correct page. Especially useful if you move templates or pages around, or have just installed EPiServer and have a lot of old urls that is no longer available.</p>
</blockquote>
<p><a href="https://www.coderesort.com/p/epicode/wiki/404Handler">404 handlers wiki page</a> explains in detail what you need to do to install the module, so I&#8217;m not going to repeat it here. Instead we&#8217;ll take a look at the code. </p>
<p>Start by doing a SVN checkout of the source code (the svn url is https://www.coderesort.com/svn/epicode/BVNetwork.404Handler/5.x/).</p>
<p><img src="http://www.frederikvig.com/wp-content/uploads/EPiServer-code-walkthrough/404handler/checkout.png" alt="SVN checkout of 404 handler" /></p>
<p>When opening up the BVNetwork.404Handler folder you&#8217;ll see a readme.txt file explaining the purpose of the module, installation, configuration etc. This is something I like! Not everyone reads the wiki page, and we as developers are especially lazy when it comes to reading documentation. Having a readme.txt with everything you need makes this so much easier, and gives the module author less support questions to answer. When using a new module, always make sure to read the documentation before asking the author questions. Saves both parties time <img src='http://www.frederikvig.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
<p>Lets open up BVNetwork.404Handler.csproj in Visual Studio.</p>
<p><img src="http://www.frederikvig.com/wp-content/uploads/EPiServer-code-walkthrough/404handler/visual-studio-project-structure.png" alt="404 handler project structure in Visual Studio" /></p>
<p>As you can see the project is structured pretty nice, with good separations between the different parts. Very good that the project uses languages files, and that they&#8217;ve included them for five different languages. Not all modules use the language files, and if they do, they seldom have any more than one update-to-date English language file. Kudos for this. </p>
<p>What I don&#8217;t like is the missing fnf_logo.gif image file in the Images folder. A quick search in Visual Studio shows that this file is no longer in use, and should therefore be removed from the project. A missing image file is not the end of the world, and I know people make mistakes/forget to commit all their files, but this can be very annoying and even lead to a lot of work for other developers using your code or taking over a project. </p>
<p>Always make sure that your project builds on other computers than your own. I recommend manually setting up the project on preferably a new computer to see that everything works as expected, you can also use the same computer, but make sure to do the normal process a new developer would use when setting up the project (new checkout etc). Especially on larger projects that have quite a few things to setup you should do this. You&#8217;ll also receive some valuable feedback if your setup process is to complex (again on larger projects this happens quite frequently). Another thing you should use is a <a href="http://en.wikipedia.org/wiki/Continuous_integration">build server</a>. There are <a href="http://www.jetbrains.com/teamcity/">quite</a> a <a href="http://cruisecontrol.sourceforge.net/">few</a> out there, I know CodeResort just added <a href="http://bitten.edgewall.org/">Bitten</a> as their build server for CodeResort projects. In a nutshell what a build server does is make sure you&#8217;ve included all the files and resources needed to build your project, run various tests (if you have any), deploy your files, create reports, notify team members if their build fails, and a bunch of other stuff, automatically for you. I&#8217;ll try to write a blog post up with more information on build and continuous integration servers.</p>
<p>Lets get back to the Visual Studio and the project! One of the things you should start out with is actually making sure the project builds after doing a checkout. So, either press ctrl + shift + b or go to Build -> Build BVNetwork.404Handler. You should have a successful build.</p>
<p>If we take a look through the code we see that most of the code is well documented and follows a nice naming convention making it easy to know what the purpose of the class is (CustomRedirectHandler.cs, CustomRedirectCollection.cs, Custom404Handler.cs etc). But we also see a few minor things we can clean up: unused using statements, commented out code, unused field variables etc. These are minor, but still important things to get rid of. Always strive for a clean code base, commented out code is something you should never commit into a repository, the whole reason for having a source control system is so that you can look at previous changesets and their code, there is no reason to keep the commented out code there, it will only be forgotten by the developer who commented out the code, and the other developers don&#8217;t know what to do with it, and will most likely just let it be. When I come across this I show no mercy and just delete it! </p>
<p>You&#8217;ll also see a few System.Diagnostics.Debug.WriteLine that are commented out. The project now uses Log4Net to log errors and warnings, System.Diagnostics.Debug.WriteLine is legacy code that we can safely remove. Another thing that I prefer is using string.Empty(); instead of &#8220;&#8221;, I&#8217;ve not updated the code because I feel this is more a personal preference. Same thing when it comes to over-documenting-code, like in this example.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
<span style="color: #008080; font-style: italic;">/// The refering url</span>
<span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetReferer<span style="color: #000000;">&#40;</span><span style="color: #000000;">System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span></span>.<span style="color: #0000FF;">Page</span> page<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #FF0000;">string</span> referer <span style="color: #008000;">=</span> page.<span style="color: #0000FF;">Request</span>.<span style="color: #0000FF;">ServerVariables</span><span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;HTTP_REFERER&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>referer <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// Strip away host name in front, if local redirect</span>
	<span style="color: #FF0000;">string</span> hostUrl <span style="color: #008000;">=</span> EPiServer.<span style="color: #0000FF;">Configuration</span>.<span style="color: #0000FF;">Settings</span>.<span style="color: #0000FF;">Instance</span>.<span style="color: #0000FF;">SiteUrl</span>.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>referer.<span style="color: #0000FF;">StartsWith</span><span style="color: #000000;">&#40;</span>hostUrl<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	    referer <span style="color: #008000;">=</span> referer.<span style="color: #0000FF;">Remove</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">0</span>, hostUrl.<span style="color: #0000FF;">Length</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
    <span style="color: #0600FF;">else</span>
	referer <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;&quot;</span><span style="color: #008000;">;</span> <span style="color: #008080; font-style: italic;">// Can't have null</span>
    <span style="color: #0600FF;">return</span> referer<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The document header can safely be removed since the method name does a good job at describing what the purpose of the method is. I&#8217;ve not removed the document header, since again this is my personal preference.</p>
<p>A thing I just noticed is that this is actually a Visual Studio class project, and not a Web Application project. I can only guess, but this is probably a project that got upgraded from Visual Studio 2003, I&#8217;ve previously had some problem upgrading a project from Visual Studio 2003 to Visual Studio 2008. The conversion usually goes okay (just an update to the csproj file mostly), but the ProjectTypeGuids doesn&#8217;t always get added. This is easy to fix, open up BVNetwork.404Handler.csproj in notepad or another source editor, and add this line.</p>

<div class="wp_syntax"><div class="code"><pre class="xml" style="font-family:monospace;"><span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;ProjectTypeGuids<span style="color: #000000; font-weight: bold;">&gt;</span></span></span>{349c5851-65df-11da-9384-00065b846f21};{fae04ec0-301f-11d3-bf4b-00c04f79efbc}<span style="color: #009900;"><span style="color: #000000; font-weight: bold;">&lt;/ProjectTypeGuids<span style="color: #000000; font-weight: bold;">&gt;</span></span></span></pre></div></div>

<p>Save, and open up the project in Visual Studio. You should now see a slightly different icon at the top of the solution explorer window.</p>
<p><img src="http://www.frederikvig.com/wp-content/uploads/EPiServer-code-walkthrough/404handler/new-icon.png" alt="New project icon in Visual Studio" /></p>
<p>This will allow us to add a designer file to default.aspx from the admin folder. To do this simply right-click the file in solution explorer and choose &#8220;Convert to Web Application&#8221;. We can now delete the &#8220;Web Form Designer generated code&#8221;-region.</p>
<p>After all these updates its very important to make sure that the project still builds and that everything functions as expected by testing it.</p>
<p>What I liked the most with this project is how it uses logging. I&#8217;m personally very bad at using logging, and know that not all projects use logging as much as they should. Kudos to the authors for this!</p>
<p>I hope you&#8217;ve learned a few new things while reading this code, and be sure to try out the 404 handler! For SEO and user experience purposes it is crucial that the users have a smooth transition. They shouldn&#8217;t even notice the change when switching to EPiServer from another CMS (that uses different urls). A 404 (file not found) error message can also quickly become a major leak of traffic for your clients site.<strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/12/part-1-setting-up-the-development-environment-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 4, 2009">Part 1: Setting up the development environment &#8211; Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2010/01/2010/" rel="bookmark" title="January 9, 2010">2010</a></li>
<li><a href="http://www.frederikvig.com/2010/02/visual-studio-2010-episerver-snippets/" rel="bookmark" title="February 11, 2010">Visual Studio 2010 EPiServer Snippets</a></li>
<li><a href="http://www.frederikvig.com/2009/12/part-8-preparing-for-launch-create-an-episerver-site-from-scratch/" rel="bookmark" title="December 24, 2009">Part 8: Preparing for launch – Create an EPiServer site from scratch</a></li>
<li><a href="http://www.frederikvig.com/2010/04/creating-a-simple-image-gallery-with-episerver/" rel="bookmark" title="April 3, 2010">Creating a simple image gallery with EPiServer</a></li>
</ul>
<p><!-- Similar Posts took 15.770 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2010/01/episerver-code-walkthrough-1-404-handler/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Removing duplicates from a PageDataCollection</title>
		<link>http://www.frederikvig.com/2009/11/removing-duplicates-from-a-pagedatacollection/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=removing-duplicates-from-a-pagedatacollection</link>
		<comments>http://www.frederikvig.com/2009/11/removing-duplicates-from-a-pagedatacollection/#comments</comments>
		<pubDate>Fri, 27 Nov 2009 16:22:54 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[EPiServer]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=529</guid>
		<description><![CDATA[Today I had to remove duplicate pages from a PageDataCollection. I checked for a method that would help me with this in the SDK, but couldn&#8217;t find one. I then went to the Filters namespace to see if there was a filter for this, but no luck. I then remembered that System.Linq has a great [...]]]></description>
			<content:encoded><![CDATA[<p>Today I had to remove duplicate pages from a PageDataCollection. I checked for a method that would help me with this in the <a href="http://sdk.episerver.com/library/cms6/html/T_EPiServer_Core_PageDataCollection.htm">SDK</a>, but couldn&#8217;t find one. I then went to the <a href="http://sdk.episerver.com/library/cms6/html/N_EPiServer_Filters.htm">Filters namespace</a> to see if there was a filter for this, but no luck.</p>
<p>I then remembered that System.Linq has a great extension method for collections that implement IEnumerable, called Distinct, that does exactly what I want. </p>
<p>The code is pretty simple.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// using System.Linq;</span>
myPageDataCollection.<span style="color: #0000FF;">Distinct</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p>Simple and elegant, but of course it didn&#8217;t work! </p>
<h3>Custom comparer</h3>
<p>If you take a look at the <a href="http://msdn.microsoft.com/en-us/library/system.linq.enumerable.distinct.aspx">documentation for the Distinct method</a> you&#8217;ll see an overload method that takes IEqualityComparer(T) for comparing.</p>
<p>Below is a custom comparer for PageData, that implements the IEqualityComparer interface. Pretty simple code.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> PageDataComparer <span style="color: #008000;">:</span> IEqualityComparer<span style="color: #008000;">&lt;</span>PageData<span style="color: #008000;">&gt;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> Equals<span style="color: #000000;">&#40;</span>PageData a, PageData b<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> a.<span style="color: #0000FF;">PageLink</span>.<span style="color: #0000FF;">CompareToIgnoreWorkID</span><span style="color: #000000;">&#40;</span>b.<span style="color: #0000FF;">PageLink</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">int</span> GetHashCode<span style="color: #000000;">&#40;</span>PageData pageData<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">return</span> pageData.<span style="color: #0000FF;">PageLink</span>.<span style="color: #0000FF;">GetHashCode</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The updated call to the Distinct method now looks like this.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">myPageDataCollection.<span style="color: #0000FF;">Distinct</span><span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> PageDataComparer<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<h3>Custom filter</h3>
<p>We can do the same with a custom filter.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> FilterRemoveDuplicates <span style="color: #008000;">:</span> IPageFilter
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Filter<span style="color: #000000;">&#40;</span>PageDataCollection pages<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		var pageReferences <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> List<span style="color: #008000;">&lt;</span>PageReference<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF;">for</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">int</span> pageIndex <span style="color: #008000;">=</span> pages.<span style="color: #0000FF;">Count</span> <span style="color: #008000;">-</span> <span style="color: #FF0000;">1</span><span style="color: #008000;">;</span> pageIndex <span style="color: #008000;">&gt;=</span> <span style="color: #FF0000;">0</span><span style="color: #008000;">;</span> pageIndex<span style="color: #008000;">--</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
			PageData pageData <span style="color: #008000;">=</span> pages<span style="color: #000000;">&#91;</span>pageIndex<span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
			<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>pageReferences.<span style="color: #0000FF;">Contains</span><span style="color: #000000;">&#40;</span>pageData.<span style="color: #0000FF;">PageLink</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
			<span style="color: #000000;">&#123;</span>
				pages.<span style="color: #0000FF;">RemoveAt</span><span style="color: #000000;">&#40;</span>pageIndex<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #000000;">&#125;</span>
			<span style="color: #0600FF;">else</span>
			<span style="color: #000000;">&#123;</span>
				pageReferences.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>pageData.<span style="color: #0000FF;">PageLink</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
			<span style="color: #000000;">&#125;</span>
		<span style="color: #000000;">&#125;</span>  
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">void</span> Filter<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, FilterEventArgs e<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Pages</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	<span style="color: #0600FF;">public</span> <span style="color: #FF0000;">bool</span> ShouldFilter<span style="color: #000000;">&#40;</span>PageData page<span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		<span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> NotImplementedException<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">new</span> Filters.<span style="color: #0000FF;">FilterRemoveDuplicates</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Filter</span><span style="color: #000000;">&#40;</span>myPageDataCollection<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/06/episerver-filter-part-2/" rel="bookmark" title="June 28, 2009">EPiServer filter – part 2: create your own filter</a></li>
<li><a href="http://www.frederikvig.com/2009/05/episerver-filter-part-1/" rel="bookmark" title="May 28, 2009">EPiServer filter &#8211; part 1</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-pagelist/" rel="bookmark" title="July 20, 2009">EPiServer web controls: PageList</a></li>
<li><a href="http://www.frederikvig.com/2009/09/extending-search-field-with-suggestion-box/" rel="bookmark" title="September 17, 2009">Extending search field with suggestion box</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-newslist/" rel="bookmark" title="July 25, 2009">EPiServer web controls: NewsList</a></li>
</ul>
<p><!-- Similar Posts took 12.809 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/11/removing-duplicates-from-a-pagedatacollection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SlideShare .NET API Wrapper</title>
		<link>http://www.frederikvig.com/2009/10/slideshare-net-api-wrapper/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=slideshare-net-api-wrapper</link>
		<comments>http://www.frederikvig.com/2009/10/slideshare-net-api-wrapper/#comments</comments>
		<pubDate>Sun, 18 Oct 2009 13:29:58 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[SlideShare]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=322</guid>
		<description><![CDATA[In a recent project I had to work with the SlideShare API. Thankfully there was some good documentation to get me started, and even a .NET wrapper for the first version of the API. From SlideShare SlideShare is a business media site for sharing presentations, documents and pdfs. After downloading and playing around with the [...]]]></description>
			<content:encoded><![CDATA[<p>In a recent project I had to work with the <a href="http://www.slideshare.net/developers">SlideShare API</a>. Thankfully there was some good <a href="http://www.slideshare.net/developers/documentation">documentation</a> to get me started, and even a <a href="http://www.slideshare.net/developers/apikits">.NET wrapper for the first version of the API</a>. </p>
<blockquote><p>
<cite><a href="http://www.slideshare.net/about">From SlideShare</a></cite></p>
<p>SlideShare is a business media site for sharing presentations, documents and pdfs.</p>
</blockquote>
<p>After downloading and playing around with the code I decided to upgrade it to version 2 of the API. I encourage you to take a look at the documentation if you haven&#8217;t, to see what&#8217;s new in version 2 of the API, and what&#8217;s available.</p>
<h3>SlideShare API Wrapper Methods</h3>
<p>Here are the methods that I&#8217;ve exposed and made available for you to use. Big thanks to <a href="http://www.briangrinstead.com/blog/about">Brian Grinstead</a> for his blog post <a href="http://www.briangrinstead.com/blog/multipart-form-post-in-c">Multipart Form Post in C#</a> and for <a href="http://groups.google.com/group/slideshare-developers/web/slideshare-api-in-net-sample-code">Gaurav Gupta</a> for creating the wrapper class for the first version, which this code is based on.</p>
<ul>
<li>GetSlideshow</li>
<li>GetSlideshowsForTag</li>
<li>GetSlideshowsForGroup</li>
<li>GetSlideshowsForUser</li>
<li>SlideshowSearch</li>
<li>GetUserGroups</li>
<li>GetUserContacts</li>
<li>GetUserTags</li>
<li>EditSlideshow</li>
<li>DeleteSlideshow</li>
<li>UploadSlideshow</li>
</ul>
<p>To use it simply download the code (see link at the bottom of this post), copy the SlideShareAPI.dll into your bin folder and make a reference to it in your project. After you&#8217;ve done that you&#8217;ll be able to create an instance of the SlideShare class which will expose the methods above.</p>
<p>Remember that you also need  an API Key and Shared Secret. Go to the <a href="http://www.slideshare.net/developers/applyforapi">Apply for API Keys page</a> and fill out the form. You should then receive an email with both keys. </p>
<h3>Example</h3>
<p>Lets get some slideshows that are tagged with web, bind them to a Repeater control and display them to the user.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Xml.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">SlideShareAPI</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> FV.<span style="color: #0000FF;">Templates</span>.<span style="color: #0000FF;">FV</span>.<span style="color: #0000FF;">Pages</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> SlideShareTest <span style="color: #008000;">:</span> <span style="color: #000000;">System.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">UI</span></span>.<span style="color: #0000FF;">Page</span>
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnLoad<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnLoad</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            var slideShare <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> SlideShare<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;API Key&quot;</span>, <span style="color: #666666;">&quot;Shared secret&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            var xml <span style="color: #008000;">=</span> XElement.<span style="color: #0000FF;">Parse</span><span style="color: #000000;">&#40;</span>slideShare.<span style="color: #0000FF;">GetSlideshowsForTag</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;web&quot;</span>, <span style="color: #FF0000;">0</span>, <span style="color: #FF0000;">10</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            var slideshows <span style="color: #008000;">=</span> from slideshare <span style="color: #0600FF;">in</span> xml.<span style="color: #0000FF;">Elements</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Slideshow&quot;</span><span style="color: #000000;">&#41;</span>
                            select <span style="color: #008000;">new</span>
                            <span style="color: #000000;">&#123;</span>
                                Title <span style="color: #008000;">=</span> slideshare.<span style="color: #0000FF;">Element</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Title&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Value</span>,
                                Description <span style="color: #008000;">=</span> slideshare.<span style="color: #0000FF;">Element</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Description&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Value</span>,
                                EmbedCode <span style="color: #008000;">=</span> slideshare.<span style="color: #0000FF;">Element</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Embed&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Value</span>
                            <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
            rptSlideshows.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> slideshows<span style="color: #008000;">;</span>
            rptSlideshows.<span style="color: #0000FF;">DataBind</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>I use Linq to XML and create anonymous objects that I then databind to my Repeater.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ Page Language<span style="color: #008000;">=</span><span style="color: #666666;">&quot;C#&quot;</span> AutoEventWireup<span style="color: #008000;">=</span><span style="color: #666666;">&quot;true&quot;</span> CodeBehind<span style="color: #008000;">=</span><span style="color: #666666;">&quot;SlideShareTest.aspx.cs&quot;</span> Inherits<span style="color: #008000;">=</span><span style="color: #666666;">&quot;FV.Templates.FV.Pages.SlideShareTest&quot;</span> <span style="color: #008000;">%&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;!</span>DOCTYPE html <span style="color: #0600FF;">PUBLIC</span> <span style="color: #666666;">&quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;</span> <span style="color: #666666;">&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;</span><span style="color: #008000;">&gt;</span>
&nbsp;
<span style="color: #008000;">&lt;</span>html xmlns<span style="color: #008000;">=</span><span style="color: #666666;">&quot;http://www.w3.org/1999/xhtml&quot;</span> <span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>head runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>title<span style="color: #008000;">&gt;&lt;/</span>title<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>head<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>body<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>form id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;form1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Repeater runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;rptSlideshows&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>HeaderTemplate<span style="color: #008000;">&gt;&lt;</span>ul<span style="color: #008000;">&gt;&lt;/</span>HeaderTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>ItemTemplate<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>li<span style="color: #008000;">&gt;</span>
        <span style="color: #008000;">&lt;</span>h3<span style="color: #008000;">&gt;&lt;%</span><span style="color: #008080;"># HttpUtility.HtmlEncode(Eval(&quot;Title&quot;).ToString()) %&gt;&lt;/h3&gt;</span>
        <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;%</span><span style="color: #008080;"># HttpUtility.HtmlEncode(Eval(&quot;Description&quot;).ToString()) %&gt;&lt;/p&gt;</span>
        <span style="color: #008000;">&lt;%</span><span style="color: #008080;"># HttpUtility.HtmlDecode(Eval(&quot;EmbedCode&quot;).ToString())%&gt;</span>
        <span style="color: #008000;">&lt;/</span>li<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>ItemTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>FooterTemplate<span style="color: #008000;">&gt;&lt;/</span>ul<span style="color: #008000;">&gt;&lt;/</span>FooterTemplate<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>Repeater<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>form<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>body<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>html<span style="color: #008000;">&gt;</span></pre></div></div>

<p>Most of the code is commented and available through Visual Studio Intellisense. You can also go through and change the code to your needs.</p>
<p><a href="http://www.frederikvig.com/wp-content/uploads/slideshare/SlideShareAPI.zip">Download the code</a><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/10/slideshare-dynamic-content/" rel="bookmark" title="October 25, 2009">SlideShare Dynamic Content</a></li>
<li><a href="http://www.frederikvig.com/2009/11/epicode-extensions-new-epicode-community-project/" rel="bookmark" title="November 1, 2009">EPiCode.Extensions new EPiCode Community Project</a></li>
<li><a href="http://www.frederikvig.com/2009/05/css-tricks-part-1/" rel="bookmark" title="May 31, 2009">CSS tricks &#8211; part 1</a></li>
<li><a href="http://www.frederikvig.com/2010/03/updated-all-episerver-posts-for-episerver-cms-6/" rel="bookmark" title="March 28, 2010">Updated all EPiServer posts for EPiServer CMS 6</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-pagelist/" rel="bookmark" title="July 20, 2009">EPiServer web controls: PageList</a></li>
</ul>
<p><!-- Similar Posts took 8.936 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/10/slideshare-net-api-wrapper/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Adding CSS and JavaScript files dynamically to your ASP.NET page</title>
		<link>http://www.frederikvig.com/2009/08/adding-css-and-javascript-files-dynamically-to-your-asp-net-page/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=adding-css-and-javascript-files-dynamically-to-your-asp-net-page</link>
		<comments>http://www.frederikvig.com/2009/08/adding-css-and-javascript-files-dynamically-to-your-asp-net-page/#comments</comments>
		<pubDate>Sat, 15 Aug 2009 13:54:44 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=164</guid>
		<description><![CDATA[When starting a new project I always create a Master Page that holds the content that is most used across the site. In my Master Page I have a PlaceHolder for my JavaScript files at the bottom of the page, right before the closing body tag. &#60;body&#62; &#60;form id=&#34;form1&#34; runat=&#34;server&#34;&#62; ... &#60;/form&#62; &#60;asp:PlaceHolder runat=&#34;server&#34; ID=&#34;phdBottomScripts&#34; [...]]]></description>
			<content:encoded><![CDATA[<p>When starting a new project I always create a <a href="http://msdn.microsoft.com/en-us/library/wtxbf3hh.aspx">Master Page</a> that holds the content that is most used across the site. In my Master Page I have a <a href="http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.placeholder.aspx">PlaceHolder</a> for my JavaScript files at the bottom of the page, right before the closing body tag.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>body<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;</span>form id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;form1&quot;</span> runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span><span style="color: #008000;">&gt;</span>
...
<span style="color: #008000;">&lt;/</span>form<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>PlaceHolder runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;phdBottomScripts&quot;</span> <span style="color: #008000;">/&gt;</span>
<span style="color: #008000;">&lt;/</span>body<span style="color: #008000;">&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> PlaceHolder BottomScriptsPlaceHolder
<span style="color: #000000;">&#123;</span>
    get
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">return</span> phdBottomScripts<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The reason for having it at the bottom instead of the head is <a href="http://developer.yahoo.com/performance/rules.html#js_bottom">performance</a>.</p>
<p>Now I have the ability to add JavaScript files to the bottom and CSS and JavaScript files to the head (through the pages Header property).</p>
<p>Lets add two methods for adding CSS and JavaScript files.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// using System.Web.UI.HtmlControls;</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> HtmlLink CreateCssLink<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> cssFilePath, <span style="color: #FF0000;">string</span> media<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	var link <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlLink<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	link.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;type&quot;</span>, <span style="color: #666666;">&quot;text/css&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	link.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;rel&quot;</span>, <span style="color: #666666;">&quot;stylesheet&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	link.<span style="color: #0000FF;">Href</span> <span style="color: #008000;">=</span> link.<span style="color: #0000FF;">ResolveUrl</span><span style="color: #000000;">&#40;</span>cssFilePath<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>media<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
		media <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;all&quot;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
&nbsp;
	link.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;media&quot;</span>, media<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #0600FF;">return</span> link<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> HtmlGenericControl CreateJavaScriptLink<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> scriptFilePath<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	var script <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HtmlGenericControl<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	script.<span style="color: #0000FF;">TagName</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;script&quot;</span><span style="color: #008000;">;</span>
	script.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;type&quot;</span>, <span style="color: #666666;">&quot;text/javascript&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	script.<span style="color: #0000FF;">Attributes</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;src&quot;</span>, script.<span style="color: #0000FF;">ResolveUrl</span><span style="color: #000000;">&#40;</span>scriptFilePath<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">return</span> script<span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The media attribute is to specify which media types the CSS file should be applied to. </p>
<h3>Media types</h3>
<ul>
<li>all</li>
<li>braille</li>
<li>embossed</li>
<li>handheld</li>
<li>print</li>
<li>projection</li>
<li>screen</li>
<li>speech</li>
<li>tty</li>
<li>tv</li>
</ul>
<h3>Example</h3>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnLoad<span style="color: #000000;">&#40;</span>EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnLoad</span><span style="color: #000000;">&#40;</span>e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	Page.<span style="color: #0000FF;">Header</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>Helper.<span style="color: #0000FF;">CreateJavaScriptLink</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;~/Scripts/swfobject.js&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	Page.<span style="color: #0000FF;">Header</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>Helper.<span style="color: #0000FF;">CreateCssLink</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;~/Styles/styles.css&quot;</span>, <span style="color: #666666;">&quot;screen&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;"><span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">head</span>&gt;</span>
...
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/Scripts/swfobject.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">link</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/css&quot;</span> <span style="color: #000066;">rel</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;stylesheet&quot;</span> <span style="color: #000066;">href</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/Styles/styles.css&quot;</span> <span style="color: #000066;">media</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;screen&quot;</span> <span style="color: #66cc66;">/</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">head</span>&gt;</span></pre></div></div>

<p>To add JavaScript files to the bottom we need to add MasterType to our .aspx file to make my Master Page strongly typed (and thus able to access the BottomScriptsPlaceHolder property).</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;%</span>@ MasterType VirtualPath<span style="color: #008000;">=</span><span style="color: #666666;">&quot;~/MasterPages/MasterPage.master&quot;</span> <span style="color: #008000;">%&gt;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">Master.<span style="color: #0000FF;">BottomScriptsPlaceHolder</span>.<span style="color: #0000FF;">Controls</span>.<span style="color: #0000FF;">Add</span><span style="color: #000000;">&#40;</span>Helper.<span style="color: #0000FF;">CreateJavaScriptLink</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;~/Scripts/master.js&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="html4strict" style="font-family:monospace;">...
<span style="color: #009900;">&lt;<span style="color: #000000; font-weight: bold;">script</span> <span style="color: #000066;">type</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;text/javascript&quot;</span> <span style="color: #000066;">src</span><span style="color: #66cc66;">=</span><span style="color: #ff0000;">&quot;/Scripts/master.js&quot;</span>&gt;&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">script</span>&gt;</span>
<span style="color: #009900;">&lt;<span style="color: #66cc66;">/</span><span style="color: #000000; font-weight: bold;">body</span>&gt;</span></pre></div></div>

<h3>Other methods</h3>
<h4>Response.Write method</h4>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>link href<span style="color: #008000;">=</span><span style="color: #666666;">&quot;&lt;%= ResolveUrl(&quot;</span>~<span style="color: #008000;">/</span>Styles<span style="color: #008000;">/</span>Styles.<span style="color: #0000FF;">css</span><span style="color: #666666;">&quot;) %&gt;&quot;</span> rel<span style="color: #008000;">=</span><span style="color: #666666;">&quot;stylesheet&quot;</span> type<span style="color: #008000;">=</span><span style="color: #666666;">&quot;text/css&quot;</span> <span style="color: #008000;">/&gt;</span></pre></div></div>

<h4>ClientScriptManager</h4>
<p><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.aspx">From MSDN</a>. </p>
<blockquote>
<p>The ClientScriptManager class is used to manage client scripts and add them to Web applications</p>
</blockquote>
<p>Methods of the ClientScriptManager class.</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerclientscriptblock.aspx">RegisterClientScriptBlock</a> &#8211; adds the JavaScript to the top of the page (in the body)</li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerstartupscript.aspx">RegisterStartupScript</a> &#8211; adds the JavaScript right before the closing form tag</li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.clientscriptmanager.registerclientscriptinclude.aspx">RegisterClientScriptInclude</a> &#8211; same as RegisterClientScriptBlock only with external JavaScript file instead</li>
</ul>
<h3>ResolveUrl and ResolveClientUrl</h3>
<p>Simply put, the difference between these two methods is that ResolveUrl will create a path from the sites root (/Styles/Styles.css), while ResolveClientUrl will create a path that is relative from the page the user is on. (../Styles/Styles.css).</p>
<ul>
<li><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.mobilecontrols.mobilecontrol.resolveurl.aspx">ResolveUrl</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/system.web.ui.control.resolveclienturl.aspx">ResolveClientUrl</a></li>
</ul>
<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/09/custom-property-shareit/" rel="bookmark" title="September 7, 2009">Custom Property: ShareIt</a></li>
<li><a href="http://www.frederikvig.com/2009/12/extending-pagedata-with-some-cool-html-helpers/" rel="bookmark" title="December 8, 2009">Extending PageData with some cool Html Helpers</a></li>
<li><a href="http://www.frederikvig.com/2010/06/css-and-javascript-compression-and-bundling/" rel="bookmark" title="June 20, 2010">CSS and JavaScript compression and bundling</a></li>
<li><a href="http://www.frederikvig.com/2009/08/add-class-to-body-element-with-asp-net-web-forms-and-master-pages/" rel="bookmark" title="August 27, 2009">Add class attribute to body element with ASP.NET web forms and Master Pages</a></li>
<li><a href="http://www.frederikvig.com/2009/11/specify-your-preferred-external-url-in-episerver/" rel="bookmark" title="November 7, 2009">Specify your preferred external URL in EPiServer</a></li>
</ul>
<p><!-- Similar Posts took 8.731 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/08/adding-css-and-javascript-files-dynamically-to-your-asp-net-page/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>EPiServer Link Collection Property</title>
		<link>http://www.frederikvig.com/2009/05/episerver-link-collection/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=episerver-link-collection</link>
		<comments>http://www.frederikvig.com/2009/05/episerver-link-collection/#comments</comments>
		<pubDate>Mon, 18 May 2009 18:59:38 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Snippet]]></category>
		<category><![CDATA[EPiServer]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=31</guid>
		<description><![CDATA[The EPiServer Link Collection Property allows you to add links to web pages, documents and e-mail addresses. For a nice overview see this post: EPiServer 5 R2 and Link Collection property In this example I&#8217;m going to show you how to use the link collection property to get a page reference to EPiServer pages and [...]]]></description>
			<content:encoded><![CDATA[<p>The EPiServer Link Collection Property allows you to add links to web pages, documents and e-mail addresses. For a nice overview see this post: <a href="http://marekblotny.blogspot.com/2009/02/episerver-5-r2-and-link-collection.html">EPiServer 5 R2 and Link Collection property</a>
</p>
<p>In this example I&#8217;m going to show you how to use the link collection property to get a page reference to EPiServer pages and retrieve some content from them. This could be used for a related content sidebar or something similar.</p>
<p>Start by creating a new link collection property in admin mode to an existing page type or a new one, name it RelatedContent. Then go to edit mode and add a few links to various pages.</p>
<p>Now we&#8217;ll start on the page template, open up your web form and add this markup.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008000;">&lt;</span>asp<span style="color: #008000;">:</span>Repeater runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;rptRelatedContent&quot;</span> OnItemDataBound<span style="color: #008000;">=</span><span style="color: #666666;">&quot;rptRelatedContent_ItemDataBound&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>HeaderTemplate<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;</span>ul id<span style="color: #008000;">=</span><span style="color: #666666;">&quot;relatedContent&quot;</span><span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>HeaderTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>ItemTemplate<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;</span>li<span style="color: #008000;">&gt;</span>
	    <span style="color: #008000;">&lt;</span>h3<span style="color: #008000;">&gt;&lt;</span>asp<span style="color: #008000;">:</span>HyperLink runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;lnkHeading&quot;</span> <span style="color: #008000;">/&gt;&lt;/</span>h3<span style="color: #008000;">&gt;</span>
	    <span style="color: #008000;">&lt;</span>p<span style="color: #008000;">&gt;&lt;</span>asp<span style="color: #008000;">:</span>Literal runat<span style="color: #008000;">=</span><span style="color: #666666;">&quot;server&quot;</span> ID<span style="color: #008000;">=</span><span style="color: #666666;">&quot;ltlText&quot;</span> <span style="color: #008000;">/&gt;&lt;/</span>p<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;/</span>li<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>ItemTemplate<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;</span>FooterTemplate<span style="color: #008000;">&gt;</span>
	<span style="color: #008000;">&lt;/</span>ul<span style="color: #008000;">&gt;</span>
    <span style="color: #008000;">&lt;/</span>FooterTemplate<span style="color: #008000;">&gt;</span>
<span style="color: #008000;">&lt;/</span>asp<span style="color: #008000;">:</span>Repeater<span style="color: #008000;">&gt;</span></pre></div></div>

<p>Then in your code-behind.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> Page_Load<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, EventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>IsValue<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;RelatedContent&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
	<span style="color: #008080; font-style: italic;">// using EPiServer.SpecializedProperties;</span>
	var relatedContent <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>LinkItemCollection<span style="color: #000000;">&#41;</span>CurrentPage<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;RelatedContent&quot;</span><span style="color: #000000;">&#93;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>relatedContent <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	    rptRelatedContent.<span style="color: #0000FF;">DataSource</span> <span style="color: #008000;">=</span> relatedContent<span style="color: #008000;">;</span>
	    rptRelatedContent.<span style="color: #0000FF;">DataBind</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	<span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>


<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">void</span> rptRelatedContent_ItemDataBound<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">object</span> sender, RepeaterItemEventArgs e<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>e.<span style="color: #0000FF;">Item</span>.<span style="color: #0000FF;">ItemType</span> <span style="color: #008000;">==</span> ListItemType.<span style="color: #0000FF;">Item</span> <span style="color: #008000;">||</span> e.<span style="color: #0000FF;">Item</span>.<span style="color: #0000FF;">ItemType</span> <span style="color: #008000;">==</span> ListItemType.<span style="color: #0000FF;">AlternatingItem</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
	var linkItem <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>LinkItem<span style="color: #000000;">&#41;</span>e.<span style="color: #0000FF;">Item</span>.<span style="color: #0000FF;">DataItem</span><span style="color: #008000;">;</span>
	var lnkHeading <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>HyperLink<span style="color: #000000;">&#41;</span>e.<span style="color: #0000FF;">Item</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;lnkHeading&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
	var ltlText <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span>Literal<span style="color: #000000;">&#41;</span>e.<span style="color: #0000FF;">Item</span>.<span style="color: #0000FF;">FindControl</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;ltlText&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>linkItem <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">&amp;&amp;</span> lnkHeading <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span> <span style="color: #008000;">&amp;&amp;</span> ltlText <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
	<span style="color: #000000;">&#123;</span>
	    var url <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UrlBuilder<span style="color: #000000;">&#40;</span>linkItem.<span style="color: #0000FF;">Href</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	    <span style="color: #008080; font-style: italic;">// using EPiServer.Web;</span>
	    <span style="color: #FF0000;">bool</span> isEPiServerPage <span style="color: #008000;">=</span> PermanentLinkMapStore.<span style="color: #0000FF;">ToMapped</span><span style="color: #000000;">&#40;</span>url<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
	    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>isEPiServerPage<span style="color: #000000;">&#41;</span>
	    <span style="color: #000000;">&#123;</span>
		var page <span style="color: #008000;">=</span> DataFactory.<span style="color: #0000FF;">Instance</span>.<span style="color: #0000FF;">GetPage</span><span style="color: #000000;">&#40;</span>PermanentLinkUtility.<span style="color: #0000FF;">GetPageReference</span><span style="color: #000000;">&#40;</span>url<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
		<span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>page <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
		<span style="color: #000000;">&#123;</span>
		    lnkHeading.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> page<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Heading&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #0600FF;">as</span> <span style="color: #FF0000;">string</span> <span style="color: #008000;">??</span> page.<span style="color: #0000FF;">PageName</span><span style="color: #008000;">;</span>
		    lnkHeading.<span style="color: #0000FF;">NavigateUrl</span> <span style="color: #008000;">=</span> page.<span style="color: #0000FF;">LinkURL</span><span style="color: #008000;">;</span>
&nbsp;
		    ltlText.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> GetText<span style="color: #000000;">&#40;</span>page, <span style="color: #FF0000;">255</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
		<span style="color: #000000;">&#125;</span>
	    <span style="color: #000000;">&#125;</span>
	<span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>The GetText method I usually place in a static helper class. It is just to get 255 characters of text from the pages MainIntro property or if it is empty from the MainBody property:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetText<span style="color: #000000;">&#40;</span>PageData page, <span style="color: #FF0000;">int</span> textLength<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>page <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    var text <span style="color: #008000;">=</span> page<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;MainIntro&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #0600FF;">as</span> string<span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>text<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
	text <span style="color: #008000;">=</span> page<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;MainBody&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #0600FF;">as</span> string<span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>text<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
    <span style="color: #000000;">&#123;</span>
	<span style="color: #0600FF;">return</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">// using EPiServer.Core.Html;</span>
    <span style="color: #0600FF;">return</span> TextIndexer.<span style="color: #0000FF;">StripHtml</span><span style="color: #000000;">&#40;</span>text, textLength<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>You could also add it as an extension method:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #008080; font-style: italic;">// Simply add the this keyword in front of PageData</span>
<span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetText<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> PageData page, <span style="color: #FF0000;">int</span> textLength<span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
...
<span style="color: #000000;">&#125;</span></pre></div></div>

<p>Then you can call it like this instead:</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;">ltlText.<span style="color: #0000FF;">Text</span> <span style="color: #008000;">=</span> page.<span style="color: #0000FF;">GetText</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">255</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span></pre></div></div>

<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/06/episerver-extension-methods-part-2/" rel="bookmark" title="June 16, 2009">EPiServer Extension Methods part 2</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-newslist/" rel="bookmark" title="July 25, 2009">EPiServer web controls: NewsList</a></li>
<li><a href="http://www.frederikvig.com/2009/12/extending-pagedata-with-some-cool-html-helpers/" rel="bookmark" title="December 8, 2009">Extending PageData with some cool Html Helpers</a></li>
<li><a href="http://www.frederikvig.com/2009/05/episerver-extension-methods/" rel="bookmark" title="May 4, 2009">EPiServer Extension Methods</a></li>
<li><a href="http://www.frederikvig.com/2009/07/episerver-web-controls-property/" rel="bookmark" title="July 5, 2009">EPiServer web controls: Property</a></li>
</ul>
<p><!-- Similar Posts took 11.419 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/05/episerver-link-collection/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Safely Cast from bool? to bool</title>
		<link>http://www.frederikvig.com/2009/05/cast-from-bool-to-bool/?utm_source=rss&amp;utm_medium=rss&amp;utm_campaign=cast-from-bool-to-bool</link>
		<comments>http://www.frederikvig.com/2009/05/cast-from-bool-to-bool/#comments</comments>
		<pubDate>Mon, 04 May 2009 19:50:12 +0000</pubDate>
		<dc:creator>Frederik Vig</dc:creator>
				<category><![CDATA[C#]]></category>
		<category><![CDATA[Code Snippet]]></category>

		<guid isPermaLink="false">http://www.frederikvig.com/?p=4</guid>
		<description><![CDATA[This is a little code snippet for when you need to cast a nullable type to its value type. if &#40;startPage.ShowMainFeatured.HasValue&#41; &#123; // Safe to cast if &#40;&#40;bool&#41; startPage.ShowMainFeatured&#41; &#123; mainfeatured.Visible = true; &#125; &#125; Related Posts: Add class attribute to body element with ASP.NET web forms and Master Pages Visual Studio 2010 EPiServer Snippets [...]]]></description>
			<content:encoded><![CDATA[<p>This is a little code snippet for when you need to cast a nullable type to its value type.</p>

<div class="wp_syntax"><div class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>startPage.<span style="color: #0000FF;">ShowMainFeatured</span>.<span style="color: #0000FF;">HasValue</span><span style="color: #000000;">&#41;</span>
<span style="color: #000000;">&#123;</span>
   <span style="color: #008080; font-style: italic;">// Safe to cast</span>
   <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span><span style="color: #FF0000;">bool</span><span style="color: #000000;">&#41;</span> startPage.<span style="color: #0000FF;">ShowMainFeatured</span><span style="color: #000000;">&#41;</span>
   <span style="color: #000000;">&#123;</span>
       mainfeatured.<span style="color: #0000FF;">Visible</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
   <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></div></div>

<p><strong>Related Posts:</strong>
<ul class="similar-posts">
<li><a href="http://www.frederikvig.com/2009/08/add-class-to-body-element-with-asp-net-web-forms-and-master-pages/" rel="bookmark" title="August 27, 2009">Add class attribute to body element with ASP.NET web forms and Master Pages</a></li>
<li><a href="http://www.frederikvig.com/2010/02/visual-studio-2010-episerver-snippets/" rel="bookmark" title="February 11, 2010">Visual Studio 2010 EPiServer Snippets</a></li>
<li><a href="http://www.frederikvig.com/2010/02/getting-the-page-and-episerver-currentpage-object-from-httpcontext/" rel="bookmark" title="February 20, 2010">Getting the Page and EPiServer CurrentPage object from HttpContext</a></li>
<li><a href="http://www.frederikvig.com/2009/09/creating-a-custom-episerver-paging-control/" rel="bookmark" title="September 20, 2009">Creating a Custom EPiServer Paging Control</a></li>
<li><a href="http://www.frederikvig.com/2010/04/detecting-ajax-requests-on-the-server/" rel="bookmark" title="April 6, 2010">Detecting Ajax requests on the server</a></li>
</ul>
<p><!-- Similar Posts took 10.613 ms --></p>
]]></content:encoded>
			<wfw:commentRss>http://www.frederikvig.com/2009/05/cast-from-bool-to-bool/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->