<?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>DevExpertise &#187; .NET</title>
	<atom:link href="http://www.devexpertise.com/category/net/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.devexpertise.com</link>
	<description>Practical tips and tricks for all things .NET, SharePoint, Silverlight, InfoPath, and general application development.</description>
	<lastBuildDate>Wed, 12 May 2010 14:32:33 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.4</generator>
		<item>
		<title>Implementing a LINQ version of SQL&#8217;s LIKE Operator</title>
		<link>http://www.devexpertise.com/2009/09/25/implementing-a-linq-version-of-sqls-like-operator/</link>
		<comments>http://www.devexpertise.com/2009/09/25/implementing-a-linq-version-of-sqls-like-operator/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 18:30:51 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Extension Methods]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/09/25/implementing-a-linq-version-of-sqls-like-operator/</guid>
		<description><![CDATA[One of the requirements of one of my recent projects was to implement a search page which allowed the user to enter a search term that supported wildcards.&#160; The search term could contain any number of wildcards in any position within that term. If you’ve done anything like this before, you probably know there’s nothing [...]]]></description>
			<content:encoded><![CDATA[<p>One of the requirements of one of my recent projects was to implement a search page which allowed the user to enter a search term that supported wildcards.&#160; The search term could contain any number of wildcards in any position within that term.</p>
<p>If you’ve done anything like this before, you probably know there’s nothing built-in to LINQ that supports this type of behavior.&#160; Sure, you could use a combination of <a href="http://msdn.microsoft.com/en-us/library/system.string.startswith.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">String.StartsWith</a>, <a href="http://msdn.microsoft.com/en-us/library/system.string.endswith.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">String.EndsWith</a>, or <a href="http://msdn.microsoft.com/en-us/library/system.string.contains.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">String.Contains</a>, but this could quickly become too cumbersome if there are many wildcards and/or they are scattered throughout the search term.&#160; Let’s look at a couple simple examples to illustrate…</p>
<p>Pretend for a second I was doing this in SQL, and I needed to get all values that start with the letter T.&#160; I would do this:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">select </span><span style="color: gray">* </span><span style="color: blue">from </span>SomeTable <span style="color: blue">where </span>SomeField <span style="color: gray">LIKE </span><span style="color: red">'T%'</span></pre>
</div>
<p>
  <br />The .NET/LINQ equivalent would be this:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">var </span>results = (<span style="color: blue">from </span>v <span style="color: blue">in </span>values <span style="color: blue">where </span>v.StartsWith(<span style="color: #a31515">&quot;T&quot;</span>) <span style="color: blue">select </span>v);</pre>
</div>
<p>
  <br />Not too difficult.&#160; However, what if you wanted to do the SQL-equivalent of this:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">select </span><span style="color: gray">* </span><span style="color: blue">from </span>SomeTable <span style="color: blue">where </span>SomeField <span style="color: gray">LIKE </span><span style="color: red">'%a%a%'</span></pre>
</div>
<p>
  <br />You’d have do a little creative parsing.&#160; It gets even worse when you as the developer doesn’t know what search term will be entered, how many wildcards will be included, and where in the term they appear.&#160; It all has to be dynamic. </p>
<p>I did a little poking around to see if anyone has done this before, and the only thing I could find was recommendations on using StartsWith/EndsWith/Contains, which I already ruled out.&#160; I also found the <a href="http://msdn.microsoft.com/en-us/library/system.data.linq.sqlclient.sqlmethods.like.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">SqlMethods.Like()</a> method which sounded perfect.&#160; However after further research, discovered it can <em>only</em> be used on an entity directly retrieved from a DataContext, such as this:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">using </span>(<span style="color: #2b91af">DemoDataContext </span>db = <span style="color: blue">new </span><span style="color: #2b91af">DemoDataContext</span>()){
    <span style="color: blue">var </span>results = (<span style="color: blue">from </span>v <span style="color: blue">in </span>db.SomeTable <span style="color: blue">where </span><span style="color: #2b91af">SqlMethods</span>.Like(v.SomeField, <span style="color: #a31515">&quot;*a*a*&quot;</span>) <span style="color: blue">select </span>v);
}</pre>
</div>
<p>
  <br />If you try to use the SqlMethods.Like() method on anything except a DataContext’s Table&lt;T&gt;, you’ll get the following message:</p>
<blockquote>
<p><strong><font color="#ff0000">“Method &#8216;Boolean Like(System.String, System.String)&#8217; cannot be used on the client; it is only for translation to SQL.”</font></strong></p>
</blockquote>
<p>So much for that.&#160; I decided to write my own extension method.&#160; I figured I could write one fairly easily using a regular expression, and I was right!&#160; I checked out a trusty <a href="http://regexlib.com/CheatSheet.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/regexlib.com');">RegEx cheat sheet</a> and found the following relevant metacharacters:</p>
<ul>
<li><font size="1" face="cour"><strong>^</strong>&#160;&#160;&#160;&#160; </font>Indicates the start of a string </li>
<li><font size="1" face="cour"><strong>$</strong>&#160;&#160;&#160;&#160; </font>Indicates the end of a string </li>
<li><font size="1" face="cour"><strong>* </strong>&#160;&#160;&#160; </font>Indicates zero or more of previous expression </li>
</ul>
<p>Knowing this, I wrote the following extension method:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">public static bool </span>Like(<span style="color: blue">this string </span>value, <span style="color: blue">string </span>term) {
    <span style="color: #2b91af">Regex </span>regex = <span style="color: blue">new </span><span style="color: #2b91af">Regex</span>(<span style="color: blue">string</span>.Format(<span style="color: #a31515">&quot;^{0}$&quot;</span>, term.Replace(<span style="color: #a31515">&quot;*&quot;</span>, <span style="color: #a31515">&quot;.*&quot;</span>)), <span style="color: #2b91af">RegexOptions</span>.IgnoreCase);
    <span style="color: blue">return </span>regex.IsMatch(value ?? <span style="color: blue">string</span>.Empty);
}</pre>
</div>
<p>
  <br />Which I can then use like this:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">var </span>results = (<span style="color: blue">from </span>v <span style="color: blue">in </span>values <span style="color: blue">where </span>v.Like(<span style="color: #a31515">&quot;*a*a*&quot;</span>) <span style="color: blue">select </span>v);</pre>
</div>
<p>
  <br />I can even simplify this by wrapping it up in another extension method:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">public static </span><span style="color: #2b91af">IEnumerable</span>&lt;<span style="color: blue">string</span>&gt; Like(<span style="color: blue">this </span><span style="color: #2b91af">IEnumerable</span>&lt;<span style="color: blue">string</span>&gt; source, <span style="color: blue">string </span>expression) {
    <span style="color: blue">return </span>(<span style="color: blue">from </span>s <span style="color: blue">in </span>source <span style="color: blue">where </span>s.Like(expression) <span style="color: blue">select </span>s);
}</pre>
</div>
<p>
  <br />Now all I have to do is the following:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">var </span>results = values.Like(<span style="color: #a31515">&quot;*a*a*&quot;</span>);</pre>
</div>
<p>
  <br />Finally, a quick usage example to prove it works:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">var </span>values = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt;(){
    <span style="color: #a31515">&quot;Widget&quot;</span>, <span style="color: #a31515">&quot;Gadget&quot;</span>, <span style="color: #a31515">&quot;Whatchamacallit&quot;</span>, <span style="color: #a31515">&quot;Gizmo&quot;</span>,
    <span style="color: #a31515">&quot;Thingamabob&quot;</span>, <span style="color: #a31515">&quot;Thingamajig&quot;</span>, <span style="color: #a31515">&quot;Doodad&quot;</span>, <span style="color: #a31515">&quot;Doohickey&quot;</span>};

<span style="color: blue">var </span>results = values.Like(<span style="color: #a31515">&quot;*a*a*&quot;</span>);

<span style="color: blue">foreach </span>(<span style="color: blue">string </span>result <span style="color: blue">in </span>results) {
    <span style="color: #2b91af">Console</span>.WriteLine(result);
}</pre>
</div>
<p>
  <br />Which outputs:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/ImplementingaLINQversionofSQLsLIKEOperat_C261/image.png"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/ImplementingaLINQversionofSQLsLIKEOperat_C261/image_thumb.png" width="669" height="86" /></a> </p>
<p>&#160;</p>
<p>Hopefully you’ll find this useful!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/09/25/implementing-a-linq-version-of-sqls-like-operator/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SharePoint Tip/Trick: Specifying a Relative Portal Site Connection Link</title>
		<link>http://www.devexpertise.com/2009/05/05/sharepoint-tiptrick-specifying-a-relative-portal-site-connection-link/</link>
		<comments>http://www.devexpertise.com/2009/05/05/sharepoint-tiptrick-specifying-a-relative-portal-site-connection-link/#comments</comments>
		<pubDate>Tue, 05 May 2009 17:35:56 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Object Model]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/05/05/sharepoint-tiptrick-specifying-a-relative-portal-site-connection-link/</guid>
		<description><![CDATA[There are a variety of reasons why you’d want to create multiple site collections – to avoid recommended capacity limits, to provide a logical site structure, etc.&#160; One of the drawbacks with creating multiple site collections is the lack of out-of-the-box functionality to access and share content across site collections.&#160; While portal site connections don’t [...]]]></description>
			<content:encoded><![CDATA[<p>There are a variety of reasons why you’d want to create multiple site collections – to avoid recommended capacity limits, to provide a logical site structure, etc.&#160; One of the drawbacks with creating multiple site collections is the lack of out-of-the-box functionality to access and share content across site collections.&#160; While portal site connections don’t do anything to access or pull content, it does allow you to specify a “connection” to another site collection, which appears in the global breadcrumb.&#160; This makes logical navigation easier.&#160; Consider the following example:&#160; a company needs to have separate site collections for each department (HR, accounting, IT, etc.), but there is also a “top-level”, shared area of the environment, which will be a separate site collection.&#160; When you’re in each of the departmental site collections, it would make sense to have a link back to the top-level site collection, to insinuate a logical hierarchy. Simply put, a portal site connection gives you a breadcrumb link to another site collection.</p>
<p>Let’s take a look at the above example.&#160; I created a root site collection (<em>http://intranet.devexpertise.com</em>), and also an accounting site collection (<em>http://intranet.devexpertise.com/sites/accounting</em>). When you’re on the accounting site collection, there’s no visual indication or link back to the “root” site collection:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/05/image.png"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/05/image-thumb.png" width="447" height="181" /></a> </p>
<p>By simply adding a portal site connection, we can provide a visual indication of the logical hierarchy and link back to the root site collection.&#160; To add a portal site connection, navigate to <strong>Site</strong> <strong>Settings</strong> &gt; <strong>Site Collection Administration</strong> &gt; <strong>Portal site connection</strong>, and specify a URL and a friendly name for the link:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/05/image1.png"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/05/image-thumb1.png" width="568" height="299" /></a> </p>
<p>Now, the breadcrumb will show a link to the root site collection:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/05/image2.png"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/05/image-thumb2.png" width="443" height="181" /></a> </p>
</p>
</p>
<p>Great! …as long as you’re always going to access your sites from a single URL.&#160; What if you have multiple URLs set up, such as the situation if you allow external access to your environment and have a separate external URL (<em>http://<strong>extranet</strong>.devexpertise.com</em>).&#160; The logical thing would be to just specify a relative link for the portal web address, however SharePoint won’t let you, and pops up a nice “Please enter a URL for the portal site” error:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/05/image3.png"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/05/image-thumb3.png" width="663" height="277" /></a> </p>
<p>Why is this really a problem?&#160; Well, let’s say you left it as <em>http://intranet.devexpertise.com</em>, and accessed it from <em>http://extranet.devexpertise.com.&#160; </em>The portal site connection link would still point to the intranet!</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/05/image4.png"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/05/image-thumb4.png" width="480" height="240" /></a> </p>
<p>Lovely, huh? Fortunately, you are able to easily set this to a relative link using a few lines of code:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">using </span>(<span style="color: #2b91af">SPSite </span>siteCollection = <span style="color: blue">new </span><span style="color: #2b91af">SPSite</span>(<span style="color: #a31515">&quot;http://intranet.devexpertise.com/sites/accounting&quot;</span>))
{
    siteCollection.PortalUrl = <span style="color: #a31515">&quot;/&quot;</span>;
}</pre>
</div>
<p>
  <br />That’s it!&#160; Now, no matter what URL you access the accounting site from, the portal site connection link will jump you back to the correct root site collection:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/05/image5.png"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/05/image-thumb5.png" width="465" height="240" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/05/05/sharepoint-tiptrick-specifying-a-relative-portal-site-connection-link/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
		<item>
		<title>Integrating a Custom ASP.NET Application into SharePoint (Part 4)</title>
		<link>http://www.devexpertise.com/2009/04/01/integrating-a-custom-aspnet-application-into-sharepoint-part-4/</link>
		<comments>http://www.devexpertise.com/2009/04/01/integrating-a-custom-aspnet-application-into-sharepoint-part-4/#comments</comments>
		<pubDate>Wed, 01 Apr 2009 21:48:55 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Visual Studio]]></category>
		<category><![CDATA[Features]]></category>
		<category><![CDATA[Object Model]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/04/01/integrating-a-custom-aspnet-application-into-sharepoint-part-4/</guid>
		<description><![CDATA[At the end of my last post in the Integrating a Custom Application Into SharePoint series, I had completely forgotten that I promised to describe how to package everything up into features and solution packages, and how to deploy that to SharePoint in a simple and streamlined fashion.&#160; I received a couple comments asking me [...]]]></description>
			<content:encoded><![CDATA[<p>At the end of my last post in the Integrating a Custom Application Into SharePoint series, I had completely forgotten that I promised to describe how to package everything up into features and solution packages, and how to deploy that to SharePoint in a simple and streamlined fashion.&#160; I received a couple comments asking me to make good on my promise, so here it is! Ask and ye shall receive <img src='http://www.devexpertise.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>In my last three posts <a href="http://www.devexpertise.com/2009/02/18/integrating-a-custom-aspnet-application-into-sharepoint-part-1/" >here</a>, <a href="http://www.devexpertise.com/2009/02/25/integrating-a-custom-aspnet-application-into-sharepoint-part-2/" >here</a>, and <a href="http://www.devexpertise.com/2009/03/04/integrating-a-custom-aspnet-application-into-sharepoint-part-3/" >here</a>, I began describing how to integrate a custom ASP.NET application into SharePoint.&#160; The first post focused on the essentials, and detailed how to get your application into the SharePoint LAYOUTS folder structure, specifically where to place your files and how to inherit SharePoint’s look and feel by using its master page.&#160; The second post focused on configuring permissions for your application and also demonstrated a few handy built-in controls that you can leverage to give your application that true SharePoint-like integrated look and feel.&#160; The third post focused on navigation and how to integrate that with the out-of-the-box navigation that is provided with SharePoint.</p>
<p>The concept of SharePoint features and solutions packages is not a secret, and there is no shortage of articles, blogs, and how-to’s that document them.&#160; Instead of reinventing the wheel and writing something up that describes what each of these are, here are a few excerpts I stole…err…borrowed from other sources:</p>
<p><strong>     <br /><font size="2">Features</font></strong></p>
<p>From <a href="Features allow you to test, deploy, and activate custom functionality inside Office SharePoint Server 2007 and provide a way to make functionality available across your server farm. This functionality can be custom workflows, content types, modifications to the user interface, or new templates for lists and document libraries.">MSDN</a>: </p>
<blockquote><p><em>“Features allow you to test, deploy, and activate custom functionality inside Office SharePoint Server 2007 and provide a way to make functionality available across your server farm. This functionality can be custom workflows, content types, modifications to the user interface, or new templates for lists and document libraries.”</em></p>
</blockquote>
<p>From the <a href="http://blogs.mosshosting.com/archive/2009/02/26/creating-site-columns-using-features.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/blogs.mosshosting.com');">SharePoint Developer Blog:</a></p>
<blockquote><p><em>“A SharePoint <strong>feature</strong> is a module of functionality that can be enabled at specific scopes within a SharePoint farm, namely the farm level, web application level, site collection level, and site level.&#160; SharePoint itself uses features for nearly everything it provides out of the box – the standard list definitions, the built-in site columns &amp; content types, built-in web parts, and they are even used to define what is displayed on the Site Settings page and the Site Actions menu.&#160; Each of the features, both built-in and custom ones, live within the “12” hive at 12\TEMPLATE\FEATURES, and each is contained within its own unique folder, whose name reflects the feature’s purpose.&#160; Within this folder there is one and only one required file, whose name must be <strong>feature.xml</strong>.&#160; This file defines the basic characteristics of the feature including its ID, name, description, activation scope, and visibility.&#160; Additionally this XML file can define additional information that is specific to the feature itself, such as a receiving assembly, and potentially one or more <strong>element manifests</strong>.&#160; Each element manifest that is defined is represented by an additional XML file that is also contained within the feature’s folder, and within these files is where the uniqueness of the feature comes out, as they can be used to define the set of files that the feature is going to inject into a given site, or the custom actions the feature will add to the Site Actions menu, or the site columns and/or content types that the feature will add to its targeted site, just to name a few.&#160; Finally, in addition to the element manifest XML files, the feature’s folder can contain any number of other files and folders that are needed for the feature itself, based upon its intended purposes.”</em></p>
</blockquote>
<p><strong>     <br /><font size="2">Solution Packages</font></strong></p>
<p>From <a href="http://msdn.microsoft.com/en-us/library/bb466225.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">MSDN</a>: </p>
<blockquote><p><em>“Microsoft Windows SharePoint Services 3.0 introduces a deployment mechanism named &quot;solution packages.&quot; A solution package is a CAB file with a .wsp file-name extension that contains all the files that must be deployed on the front-end Web server and a set of XML-based installation instructions. Windows SharePoint Services provides a rich infrastructure that simplifies deployment of solution packages in a Web farm environment.”</em></p>
</blockquote>
<p>From <a href="http://blogs.technet.com/wbaer/archive/2007/03/29/building-solutions-for-microsoft-office-sharepoint-server-2007-windows-sharepoint-services-3-0.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/blogs.technet.com');">Bill Baer</a>:</p>
<blockquote><p><em>“Solution packages are designed to provide the ability to develop and deploy reusable&#160; site and feature definitions, web part files, templates, assemblies, and code access security policies across one or more server farms.&#160; A solution package is a cabinet file that can contain, site and feature definitions, web part files, templates, assemblies, and code access security policies.&#160; A solution package contains a web manifest that that defines the list of features, site definitions, resource files, Web Part files, and assemblies to process when the solution is deployed.&#160; The directory structure within the cabinet file dictates the resulting structure on the web front-end computer when the solution is deployed.”</em></p>
</blockquote>
<p>&#160; <br />In the simplest terms, a feature is used to deploy something to SharePoint.&#160; One or more features can then be packaged up into a solution package, and that solution package can then be deployed to SharePoint.&#160; Got it?</p>
<p>So, what can you use a SharePoint features to deploy?&#160; Pretty much any custom development artifact.&#160; Here are just a few of the items that come to mind:</p>
<ul>
<li>Web Parts </li>
<li>Event Handlers </li>
<li>User Controls </li>
<li>Visual Studio-authored Workflows </li>
<li>Site Columns </li>
<li>Content Types </li>
<li>Site Definitions </li>
<li>List Templates </li>
<li>CSS style sheets </li>
<li>JavaScript files </li>
<li>LAYOUTS application pages </li>
<li>THEMES (I describe how <a href="http://www.devexpertise.com/2009/02/11/installing-a-theme-as-a-sharepoint-feature/" >here</a>) </li>
<li>Custom Actions </li>
<li>Delegate Controls </li>
<li>Master Pages/Page Layouts/Files/Documents/List Items </li>
<li>Site Definitions </li>
<li>Web Services </li>
<li>WCF Services </li>
<li>HTTP Modules </li>
<li>HTTP Handlers </li>
<li>Executing custom code when the feature is activated/deactivated/installed/uninstalled </li>
<li>Staple other features onto existing site definitions </li>
</ul>
<p>If you’ve developed any of these items, then you should know that many of these artifacts are deployed to somewhere in SharePoint’s “12 Hive” folder structure.&#160; Certain types of files belong in certain places in the 12 Hive.&#160; For example, images belong in the ~12\TEMPLATE\IMAGES folder, application pages belong in teh ~12\TEMPLATE\LAYOUTS folder, etc.&#160; If you’re building a custom web part, you will be placing your web part assembly either in the GAC or in SharePoint’s bin directory.&#160; If you’re deploying style sheets, then you need to place that in a different location.&#160; What am I getting at here?&#160; 9 times out of 10 when we’re deploying custom development artifacts to SharePoint, we will be placing many files in multiple locations.&#160; This is very troublesome and error-prone, because 1.) it’s very easy to miss one, or put a file in the wrong directory, 2.) it’s a tedious manual process, and 3.) it’s not the right way to do it.</p>
<p>To illustrate what I’m talking about, let’s examine the Visual Studio project I put together for this blog series.&#160; If you take a look at the following screenshot of how I have my solution set up, the important thing to notice is my folder structure, which mimics that of the 12 Hive.&#160; Inside these standard SharePoint folders, I place custom folders specific to the project I’m working on.&#160; There’s a very good reason for this.&#160; Let’s say you’re deploying a custom image to the IMAGES directory.&#160; There are over 2,000 images in that folder, and adding yours into that folder makes it hard to find and is much less maintainable.&#160; A better practice is to add your own sub-folder, then add your images to that which will isolate your files that belong to their respective solution.</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/04/image.png"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/04/image-thumb.png" width="307" height="679" /></a> </p>
<p>As you can see, I’m deploying a lot of different files. I have some images, a script file, a style sheet, etc.&#160; I also have a feature that will be used to provision Custom Actions, as I describe <a href="http://www.devexpertise.com/2009/03/04/integrating-a-custom-aspnet-application-into-sharepoint-part-3/" >here</a>.&#160; Remember, a feature is just an XML file that describes what the feature does and what should be included with it.&#160; My feature for the above solution is pretty simple, and only includes the CustomActions.xml manifest file reference:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot; <span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">utf-8</span>&quot;<span style="color: blue">?&gt;
&lt;</span><span style="color: #a31515">Feature
  </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">5856617E-BED2-4705-B030-735F7483225E</span>&quot;
  <span style="color: red">Title</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise Layouts Application</span>&quot;
  <span style="color: red">Description</span><span style="color: blue">=</span>&quot;<span style="color: blue">Contains the necessary components for the DevExpertise custom LAYOUTS application.</span>&quot;
  <span style="color: red">Version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0.0.0</span>&quot;
  <span style="color: red">Scope</span><span style="color: blue">=</span>&quot;<span style="color: blue">Web</span>&quot;
  <span style="color: red">Hidden</span><span style="color: blue">=</span>&quot;<span style="color: blue">false</span>&quot;
  <span style="color: red">ImageUrl</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise\devexpertiseLogo.png</span>&quot;
  <span style="color: red">ReceiverAssembly</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise.LayoutsApp, Version=1.0.0.0, culture=neutral, PublicKeyToken=d39eedb6cff9b1c8</span>&quot;
  <span style="color: red">ReceiverClass</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise.LayoutsApp.FeatureReceiver</span>&quot;
  <span style="color: red">xmlns</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://schemas.microsoft.com/sharepoint/</span>&quot;<span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">ElementManifests</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">ElementManifest </span><span style="color: red">Location</span><span style="color: blue">=</span>&quot;<span style="color: blue">CustomActions.xml</span>&quot; <span style="color: blue">/&gt;
  &lt;/</span><span style="color: #a31515">ElementManifests</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">Feature</span><span style="color: blue">&gt;</span></pre>
</div>
<p>
  <br />Now it’s time to deploy everything.&#160; While I could just copy all of these files to the file system manually, then install the Custom Actions feature on the SharePoint site, I instead bundle everything up in a <em>single</em> deployable solution package. Enter <a href="http://www.codeplex.com/wspbuilder" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.codeplex.com');">WSPBuilder</a>.</p>
<p>Without getting into the nasty details of actually how to create a solution package from scratch, I will say that it’s a nightmare.&#160; A solution package is a .WSP file, which is really a .CAB file.&#160; To create .CAB files, you use MakeCab.exe, which involves creating your own .DDF file and XML manifest.&#160; It’s ugly, trust me.&#160; WSPBuilder eliminates the need to manually build these files, and offers a simple command-line interface to build the package, which traverses a 12 Hive folder structure and creates the solution automatically.</p>
<p>Most anything I do frequently, I have a script for.&#160; Creating solution packages is no exception.&#160; First, in my VS solution folder on the file system, I created a Solution folder that my script will generate the package in.&#160; In addition, I included a 12 folder and a GAC folder.&#160; The 12 folder will obviously contain the folder structure for the 12 Hive, and the GAC folder will contain all assemblies that will need to be deployed to the GAC.&#160; WSPBuilder <em>automatically</em> builds this into the solution package for us.&#160; To manage my solution creation and deployment, I use 2 scripts: wsp.bat to build it, and install.bat to deploy it.</p>
<p>My wsp.bat is as follows (NOTE, the last command that builds the package should all be on one line.&#160; I had to break it up to fit into this post):</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code">@SET WSPPBUILDER=&quot;C:\Tools\WspBuilder\WspBuilder.exe&quot;
@SET SOLUTIONNAME=DevExpertise.LayoutsApp.wsp
@SET URL=http://server
@SET BUILD=Debug

ECHO Copying Files to Temporary Solution Directory
  xcopy bin\DevExpertise.LayoutsApp.dll Solution\GAC\ /y /r

ECHO Building Solution Package
  %WSPPBUILDER% -CreateWSPFileList wspfiles.txt -outputpath solution
    -12path Solution\12 -gacpath Solution\GAC -Excludepaths bin
    -createfolder true -wspname %SOLUTIONNAME%</pre>
</div>
<p>
  <br />This script only generates the .WSP file; I still need a script to install it.&#160; My install.bat file is as follows:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code">@SET STSADM=&quot;C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\BIN\STSADM&quot;
@SET SOLUTIONNAME=DevExpertise.LayoutsApp.wsp
@SET URL=http://server/

ECHO Removing Existing Solution
  %STSADM% -o retractsolution -name %SOLUTIONNAME% -url %URL% -immediate
  %STSADM% -o execadmsvcjobs
  %STSADM% -o deletesolution -name %SOLUTIONNAME%

ECHO Installing Solution
  %STSADM% -o addsolution -filename Solution\%SOLUTIONNAME%
  %STSADM% -o deploysolution -name %SOLUTIONNAME% -url %URL%  -immediate -allowGacDeployment -force
  %STSADM% -o execadmsvcjobs 

ECHO Recycling App Pool
  iisapp /a &quot;Sharepoint - 80&quot; /r</pre>
</div>
<p>&#160; <br />Now, you could just as easily fold both of these scripts into 1, but I like to be able to generate the solution package without actually deploying it sometimes.&#160; Whatever floats your boat I suppose.</p>
<p>Once your feature is installed, you will see it appear in <strong>Central Administration</strong> &gt; <strong>Operations</strong> &gt; <strong>Solution Management</strong>:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/04/image1.png"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/04/image-thumb1.png" width="604" height="154" /></a> </p>
<p>Remember, this particular solution package is essentially responsible for 3 things: deploying files to the file system, adding an assembly to the GAC, and creating a web-scoped feature.&#160; Once the solution is deployed, these will automatically be done for you:</p>
<p>Some of the files that were deployed to the LAYOUTS folder:<a href="http://www.devexpertise.com/wp-content/uploads/2009/04/image2.png" rel="lightbox"><br />
    <br /><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/04/image-thumb2.png" width="750" height="451" /></a> </p>
<p>The assembly installed in the GAC:<br />
  <br /><a href="http://www.devexpertise.com/wp-content/uploads/2009/04/image3.png"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/04/image-thumb3.png" width="584" height="228" /></a> </p>
<p>And finally the web-scoped feature:<a href="http://www.devexpertise.com/wp-content/uploads/2009/04/image4.png" rel="lightbox"><br />
    <br /><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/04/image-thumb4.png" width="752" height="160" /></a> </p>
<p>
  <br />Good stuff, huh?&#160; Hopefully you can see how easy it is to create features and solution packages, and understand <em>why</em> it is Microsoft’s recommended best practice for deploying custom SharePoint artifacts.&#160; I know it seems like a lot of work, but once you do this once or twice and realize the benefits of what features and solution packages provide, I guarantee you’ll never look back.</p>
<p>&#160;</p>
<p>Here are a few tools that may help: </p>
<ul>
<li><a href="http://www.codeplex.com/wspbuilder" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.codeplex.com');">WSP Builder</a> (a MUST have) </li>
<li><a href="http://www.codeplex.com/stsdev" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.codeplex.com');">STSDEV</a> </li>
<li><a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=7bf65b28-06e2-4e87-9bad-086e32185e68&amp;displaylang=en" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.microsoft.com');">VSeWSS 1.2 (for Visual Studio 2008)</a> </li>
<li><a href="http://www.ascentium.com/blog/sp/post29.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.ascentium.com');">SPDeploy</a> </li>
<li><a href="http://www.codeplex.com/sharepointinstaller" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.codeplex.com');">SharePoint Solution Installer</a> </li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/04/01/integrating-a-custom-aspnet-application-into-sharepoint-part-4/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>ASP.NET Tip/Trick: Use a Base Page Class for All Application Pages</title>
		<link>http://www.devexpertise.com/2009/03/25/aspnet-tiptrick-use-a-base-page-class-for-all-application-pages/</link>
		<comments>http://www.devexpertise.com/2009/03/25/aspnet-tiptrick-use-a-base-page-class-for-all-application-pages/#comments</comments>
		<pubDate>Wed, 25 Mar 2009 23:31:06 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/03/25/aspnet-tiptrick-use-a-base-page-class-for-all-application-pages/</guid>
		<description><![CDATA[All coders worth their salt know that duplicating code isn’t a best practice, and you should consolidate and leverage object inheritance where necessary.&#160; When done correctly, this promotes better maintainability and a better overall application. I’ve been doing a lot of straight ASP.NET application programming lately, and no matter how many ASP.NET applications I write, [...]]]></description>
			<content:encoded><![CDATA[<p>All coders worth their salt know that duplicating code isn’t a best practice, and you should consolidate and leverage object inheritance where necessary.&#160; When done correctly, this promotes better maintainability and a better overall application.</p>
<p>I’ve been doing a lot of straight ASP.NET application programming lately, and no matter how many ASP.NET applications I write, I always use a certain number of common methods in my pages’ code-behind.&#160; For example, I get and set view state values, I retrieve values from the cache, or verify query strings have been included.&#160; Because I’m doing these same types of things in most of my pages, it makes sense to include a lot of the leg work in a base class that each of my pages can inherit.&#160; This blog post will provide you the default base class I always start with, and will explain and demonstrate a few of the methods.</p>
<p>At a high level, my base class is divided into the following four regions:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/image4.png"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/03/image-thumb4.png" width="401" height="274" /></a> </p>
<p><strong>Query String Methods</strong>     <br />Let’s take a look at the Query String Methods first.&#160; Many pages will have support for query strings, and most of the time these query string values will need to be validated.&#160; Consider a scenario where you are accessing data from a database, and you navigate to a page with a URL of <strong>http://webapp/page.aspx?id=10</strong>.&#160; You pull out the ID query string value and pass that in as a parameter and retrieve the appropriate results.&#160; But what if you modify the query string value and access a page with a URL of <strong>http://webapp/page.aspx?id=abc</strong>?&#160; Are you checking to make sure the value is numeric? Are you even checking to make sure an ID query string has been specified?&#160; Well, you should!&#160; A lot of this logic can be wrapped in a base class, and through the use of inheritance and overridden methods, the <em>specific</em> logic can be written.&#160; </p>
<p>I have three methods declared in my base class: </p>
<ul>
<li><strong>RequiredQueryStrings</strong>: Returns a list of all required query string keys. </li>
<li><strong>CheckQueryStrings</strong>: Ensures all required query strings have been specified. </li>
<li><strong>CheckQueryStringValues</strong>: Ensures the specified query string values are actually valid. </li>
</ul>
<p>These methods are declared as follows:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">When overriden, returns a list of all required query string keys
</span><span style="color: gray">/// &lt;/summary&gt;
/// &lt;returns&gt;&lt;/returns&gt;
</span><span style="color: blue">protected virtual </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt; RequiredQueryStrings() {
    <span style="color: blue">return null</span>;
}

<span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">When overriden, checks the actual values of query strings
</span><span style="color: gray">/// &lt;/summary&gt;
/// &lt;returns&gt;&lt;/returns&gt;
</span><span style="color: blue">protected virtual bool </span>CheckQueryStringValues() {
    <span style="color: blue">return true</span>;
}

<span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">Verifies the required query string are actually present
</span><span style="color: gray">/// &lt;/summary&gt;
/// &lt;returns&gt;&lt;/returns&gt;
</span><span style="color: blue">protected bool </span>CheckQueryStrings() {
    <span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt; values = RequiredQueryStrings();

    <span style="color: blue">if </span>(values == <span style="color: blue">null </span>|| values.Count == 0) {
        <span style="color: blue">return true</span>;
    }
    <span style="color: blue">else </span>{
        <span style="color: blue">foreach </span>(<span style="color: blue">string </span>value <span style="color: blue">in </span>values) {
            <span style="color: blue">if </span>(Request.QueryString[value] == <span style="color: blue">null</span>) {
                <span style="color: blue">return false</span>;
            }
        }
    }

    <span style="color: blue">return true</span>;
}</pre>
</div>
<p>
  <br />In addition to these methods, my base page’s Init method checks these methods and depending on the results, allows the rest of the code to run or redirects you to an error page:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">protected override void </span>OnInit(<span style="color: #2b91af">EventArgs </span>e) {
    <span style="color: blue">base</span>.OnInit(e);

    <span style="color: blue">if </span>(!CheckQueryStrings()) {
        <span style="color: green">// all required query strings have not been specified
        </span>RedirectToPage(<span style="color: #a31515">&quot;Error.aspx&quot;</span>);
    }

    <span style="color: blue">if </span>(!CheckQueryStringValues()) {
        <span style="color: green">// one or more query string values are invalid
        </span>RedirectToPage(<span style="color: #a31515">&quot;Error.aspx&quot;</span>);
    }
}</pre>
</div>
<p>
  <br />To use this, I simply inherit my application pages from my PageBase class, and override the appropriate methods:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">public partial class </span><span style="color: #2b91af">ViewWidget </span>: <span style="color: #2b91af">PageBase </span>{

    <span style="color: blue">protected override </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt; RequiredQueryStrings() {
        <span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt; values = <span style="color: blue">new </span><span style="color: #2b91af">List</span>&lt;<span style="color: blue">string</span>&gt;();
        values.Add(<span style="color: #a31515">&quot;widgetID&quot;</span>);

        <span style="color: blue">return </span>values;
    }

    <span style="color: blue">protected override bool </span>CheckQueryStringValues() {
        <span style="color: blue">int </span>widgetID = 0;
        <span style="color: blue">int</span>.TryParse(Request.QueryString[<span style="color: #a31515">&quot;widgetID&quot;</span>].ToString(), <span style="color: blue">out </span>widgetID);

        <span style="color: blue">return </span>(widgetID &gt; 0);
    }

    <span style="color: blue">protected void </span>Page_Load(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e) { }
}</pre>
</div>
<p>
  <br />Notice all I’m doing is overriding the base class methods, and specifying the things that are required.&#160; It’s up to the base class to do the actual error handling, which in my case involves navigating to an error page.&#160; The important thing to note is that the error handling logic is declared in ONE place.&#160; Each individual page is only responsible for identifying the values that should be checked.</p>
<p>Now, when I access my ViewWidget.aspx page with a valid URL, such as <strong>http://webapp/ViewWidget.aspx?widgetID=10</strong>, I get the following page:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/image5.png"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/03/image-thumb5.png" width="620" height="342" /></a> </p>
<p>
  <br />If I access it with an invalid URL, such as <strong>http://webapp/ViewWidget.aspx?widgetID=xyz</strong>, I get redirected to the error page:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/image6.png"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/03/image-thumb6.png" width="620" height="342" /></a> </p>
</p>
<p>&#160;</p>
<p><strong>Redirection Methods</strong> </p>
<p>Chances are your web application contains more than just one page, and you will have to navigate to other pages.&#160; Once in awhile ASP.NET will throw a ThreadAbortException when redirecting to another page, which doesn’t matter, and we don’t really need to do anything when that occurs.&#160; My redirection methods consist of two methods:</p>
<ul>
<li><strong>RedirectToPage</strong>: Redirects to a page and ignores the exception that is sometimes thrown. </li>
<li><strong>RedirectToPageWithQueryStrings</strong>: Redirects to a page and includes all current query string keys and values.&#160; Since this method ultimately calls RedirectToPage, any exception is also ignored. </li>
</ul>
<p>These methods are declared as follows:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">Redirects the application to the specified page, and ignores the
</span><span style="color: gray">/// </span><span style="color: green">erroneous error that is sometimes thrown
</span><span style="color: gray">/// &lt;/summary&gt;
/// &lt;param name=&quot;url&quot;&gt;&lt;/param&gt;
</span><span style="color: blue">protected void </span>RedirectToPage(<span style="color: blue">string </span>url){
    <span style="color: blue">try</span>{
        Response.Redirect(url);
    }
    <span style="color: blue">catch</span>{
        <span style="color: green">// catch the ThreadAbortException that is occasionally thrown by ASP.NET
    </span>}
}</pre>
<pre class="code"><span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">Redirects to another page and carries over all current
</span><span style="color: gray">/// </span><span style="color: green">query string keys and values
</span><span style="color: gray">/// &lt;/summary&gt;
/// &lt;param name=&quot;url&quot;&gt;&lt;/param&gt;
</span><span style="color: blue">protected void </span>RedirectToPageWithQueryStrings(<span style="color: blue">string </span>url) {
    <span style="color: blue">string </span>queryStringList = <span style="color: blue">string</span>.Empty;

    <span style="color: blue">if </span>(!<span style="color: blue">string</span>.IsNullOrEmpty(url)) {
        <span style="color: blue">if </span>(Request.QueryString.Count &gt; 0){

            <span style="color: green">// rebuild the query string list
            </span><span style="color: blue">for</span>(<span style="color: blue">int </span>i = 0; i &lt; Request.QueryString.Count;i++){
                queryStringList += <span style="color: blue">string</span>.Format(<span style="color: #a31515">&quot;{0}={1}&amp;&quot;</span>,
                    Request.QueryString.GetKey(i), Request.QueryString.Get(i));
            }

            <span style="color: green">// remove the erroneous ampersand
            </span>queryStringList = queryStringList.TrimEnd(<span style="color: blue">new char</span>[] { <span style="color: #a31515">'&amp;' </span>});

            <span style="color: green">// append the '?' to the beginning
            </span><span style="color: blue">if </span>(!<span style="color: blue">string</span>.IsNullOrEmpty(queryStringList)) {
                url = <span style="color: #a31515">&quot;?&quot; </span>+ queryStringList;
            }
        }

        RedirectToPage(url);
    }
}</pre>
</div>
<p>&#160;</p>
<p><strong>View State Methods</strong> </p>
<p>I utilize view state occasionally, and have included a couple methods to help manage this:</p>
<ul>
<li><strong>GetViewStateValue</strong>: Retrieves a value from view state, and if it doesn’t exist returns the specified default value. </li>
<li><strong>SetViewStateValue</strong>: Sets a view state value. </li>
<li><strong>ClearViewStateValue</strong>: Clears a view state value. </li>
</ul>
<p>These methods are declared as follows:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">Retrieves a value from ViewState
</span><span style="color: gray">/// &lt;/summary&gt;
/// &lt;param name=&quot;key&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;defaultValue&quot;&gt;&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
</span><span style="color: blue">protected object </span>GetViewStateValue(<span style="color: blue">string </span>key, <span style="color: blue">object </span>defaultValue) {
    <span style="color: blue">return </span>((ViewState[key] == <span style="color: blue">null</span>) ? defaultValue : ViewState[key]);
}

<span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">Sets a value in ViewState
</span><span style="color: gray">/// &lt;/summary&gt;
/// &lt;param name=&quot;key&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;val&quot;&gt;&lt;/param&gt;
</span><span style="color: blue">protected void </span>SetViewStateValue(<span style="color: blue">string </span>key, <span style="color: blue">object </span>val) {
    ViewState[key] = val;
}

<span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">Clears a value from ViewState
</span><span style="color: gray">/// &lt;/summary&gt;
/// &lt;param name=&quot;key&quot;&gt;&lt;/param&gt;
</span><span style="color: blue">protected void </span>ClearViewStateValue(<span style="color: blue">string </span>key) {
    ViewState[key] = <span style="color: blue">null</span>;
}</pre>
</div>
<p>&#160;</p>
<p><strong>Cache Methods</strong> </p>
<p>I also leverage the application cache, and have included a few methods to help manage this as well:</p>
<ul>
<li><strong>GetCachedItem</strong>: Retrieves a value from the application cache, and if it doesn’t exist returns null. </li>
<li><strong>SetCachedItem</strong>: Adds an item to the application cache. </li>
<li><strong>ClearCachedItem</strong>: Removes an item from the application cache. </li>
</ul>
<p>These methods are declared as follows:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">Returns an item from the application cache
</span><span style="color: gray">/// &lt;/summary&gt;
/// &lt;param name=&quot;key&quot;&gt;&lt;/param&gt;
/// &lt;returns&gt;&lt;/returns&gt;
</span><span style="color: blue">protected object </span>GetCachedItem(<span style="color: blue">string </span>key) {
    <span style="color: blue">object </span>returnValue = <span style="color: blue">null</span>;

    <span style="color: blue">try </span>{
        returnValue = Cache.Get(key);
    }
    <span style="color: blue">catch </span>{ }

    <span style="color: blue">return </span>returnValue;
}

<span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">Adds in item to the application cache
</span><span style="color: gray">/// &lt;/summary&gt;
/// &lt;param name=&quot;key&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;value&quot;&gt;&lt;/param&gt;
/// &lt;param name=&quot;minutes&quot;&gt;&lt;/param&gt;
</span><span style="color: blue">protected void </span>SetCachedItem(<span style="color: blue">string </span>key, <span style="color: blue">object </span>value, <span style="color: blue">int </span>minutes) {
    <span style="color: blue">try </span>{
        Cache.Insert(key, value, <span style="color: blue">null</span>,
            <span style="color: #2b91af">DateTime</span>.Now.AddMinutes(minutes), <span style="color: #2b91af">TimeSpan</span>.Zero);
    }
    <span style="color: blue">catch </span>{ }
}

<span style="color: gray">/// &lt;summary&gt;
/// </span><span style="color: green">Clears an item from the application cache
</span><span style="color: gray">/// &lt;/summary&gt;
/// &lt;param name=&quot;key&quot;&gt;&lt;/param&gt;
</span><span style="color: blue">protected void </span>ClearCachedItem(<span style="color: blue">string </span>key) {
    <span style="color: blue">try </span>{
        Cache.Remove(key);
    }
    <span style="color: blue">catch </span>{ }
}</pre>
</div>
<p>&#160;</p>
<p>
  <br />These are just a few of the methods that are good candidates for placement in a base class.&#160; You could just as easily as methods to manage session variables, or some other type of common functionality in your application.&#160; The point is to identify places where you can <em>simplify</em> and <em>reuse</em> code.&#160; This will make it much easier to develop, maintain, and enhance in the future.</p>
<p>I’ve included my base page in the ZIP file below.&#160; As always, my code is provide as-is and without warranty!</p>
<div style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px" id="scid:fb3a1972-4489-4e52-abe7-25a00bb07fdf:75751f8d-52db-41a1-980b-e40b696e4ec3" class="wlWriterEditableSmartContent">
<p>Download: <a href="http://www.devexpertise.com/wp-content/uploads/2009/06/pagebase.zip" onclick="javascript:pageTracker._trackPageview('/downloads/wp-content/uploads/2009/06/pagebase.zip');" target="_blank">PageBase.zip</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/03/25/aspnet-tiptrick-use-a-base-page-class-for-all-application-pages/feed/</wfw:commentRss>
		<slash:comments>21</slash:comments>
		</item>
		<item>
		<title>Integrating a Custom ASP.NET Application into SharePoint (Part 3)</title>
		<link>http://www.devexpertise.com/2009/03/04/integrating-a-custom-aspnet-application-into-sharepoint-part-3/</link>
		<comments>http://www.devexpertise.com/2009/03/04/integrating-a-custom-aspnet-application-into-sharepoint-part-3/#comments</comments>
		<pubDate>Thu, 05 Mar 2009 01:58:16 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Object Model]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint UI]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[Features]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/03/04/integrating-a-custom-aspnet-application-into-sharepoint-part-3/</guid>
		<description><![CDATA[In my last two posts here and here I began describing how to integrate a custom ASP.NET application into SharePoint.&#160; The first post focused on the essentials, and detailed how to get your application into the SharePoint LAYOUTS folder structure, specifically where to place your files and how to inherit SharePoint’s look and feel by [...]]]></description>
			<content:encoded><![CDATA[<p>In my last two posts <a href="http://www.devexpertise.com/2009/02/18/integrating-a-custom-aspnet-application-into-sharepoint-part-1/" >here</a> and <a href="http://www.devexpertise.com/2009/02/25/integrating-a-custom-aspnet-application-into-sharepoint-part-2/" >here</a> I began describing how to integrate a custom ASP.NET application into SharePoint.&#160; The first post focused on the essentials, and detailed how to get your application into the SharePoint LAYOUTS folder structure, specifically where to place your files and how to inherit SharePoint’s look and feel by using its master page.&#160; The second post focused on configuring permissions for your application and also demonstrated a few handy built-in controls that you can leverage to give your application that true SharePoint-like integrated look and feel.</p>
<p>This post will explain how to add custom navigation for your application.&#160; There are a few different approaches that I like to take depending on the application, and I’ll demonstrate a couple of them for you.&#160; These can be used in any combination in order to achieve the navigation you’re aiming for.&#160; In fact, I <em>recommend</em> a combination of these to achieve a fully integrated navigation structure.</p>
<p><strong>Approach #1: Quick Launch Navigation      <br /></strong>Now, modifying the Quick Launch navigation menu is a trivial task.&#160; Simply go to Site Actions &gt; Site Settings and find the settings to modify the navigation (Quick Launch on team sites, and Navigation on publishing sites), and add and remove nodes to your heart’s content.&#160; While this manual method works just fine, it’s just that: manual.&#160; I always have the mindset of if I’m already deploying an application somewhere, I might as well automate as much of the setup steps as I can.&#160; Luckily through the use of features we are able to accomplish this easily.</p>
<p>For the sake of brevity, I am going to assume you know what a SharePoint feature is, what a solution package is, and how to create and deploy them.&#160; If not, there are plenty of great resources out there that will help you out.&#160; Anyways, the first step is to create the feature and associated feature receiver that will execute when the feature is activated on the site.&#160; The feature receiver is going to utilized the SharePoint Object Model to create navigation items.</p>
<p>The first step is to create the feature receiver, which must inherit from the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spfeaturereceiver.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">SPFeatureReceiver</a> class and must implement the standard 4 feature operations: FeatureActivated, FeatureDeactivated, FeatureInstalled, and FeatureUninstalled.&#160; For this post I’m only adding the items in the FeatureActivated event, but it’s probably a good idea to clean these up in the FeatureDeactivated event in case the feature is ever deactivated.&#160; My feature receiver looks like this:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">namespace </span>DevExpertise.LayoutsApp {
    <span style="color: blue">public class </span><span style="color: #2b91af">FeatureReceiver</span>: <span style="color: #2b91af">SPFeatureReceiver </span>{
        <span style="color: blue">public override void </span>FeatureActivated(<span style="color: #2b91af">SPFeatureReceiverProperties </span>properties) {
            <span style="color: blue">using </span>(<span style="color: #2b91af">SPWeb </span>site = (properties.Feature.Parent <span style="color: blue">as </span><span style="color: #2b91af">SPWeb</span>)) {
                <span style="color: green">// create the nodes
                </span><span style="color: #2b91af">SPNavigationNode </span>widgetManagementNode = <span style="color: blue">new </span><span style="color: #2b91af">SPNavigationNode</span>(<span style="color: #a31515">&quot;Widget Management&quot;</span>,
                    <span style="color: #2b91af">SPUrlUtility</span>.CombineUrl(site.Url, <span style="color: #a31515">&quot;DevExpertise.LayoutsApp/WidgetMgmt.aspx&quot;</span>), <span style="color: blue">true</span>);
                <span style="color: #2b91af">SPNavigationNode </span>viewWidgetsNode = <span style="color: blue">new </span><span style="color: #2b91af">SPNavigationNode</span>(<span style="color: #a31515">&quot;View Widgets&quot;</span>,
                    <span style="color: #2b91af">SPUrlUtility</span>.CombineUrl(site.Url, <span style="color: #a31515">&quot;DevExpertise.LayoutsApp/WidgetList.aspx&quot;</span>), <span style="color: blue">true</span>);
                <span style="color: #2b91af">SPNavigationNode </span>addWidgetNode = <span style="color: blue">new </span><span style="color: #2b91af">SPNavigationNode</span>(<span style="color: #a31515">&quot;Add Widget&quot;</span>,
                    <span style="color: #2b91af">SPUrlUtility</span>.CombineUrl(site.Url, <span style="color: #a31515">&quot;DevExpertise.LayoutsApp/AddWidget.aspx&quot;</span>), <span style="color: blue">true</span>);
                <span style="color: #2b91af">SPNavigationNode </span>widgetSettingsNode = <span style="color: blue">new </span><span style="color: #2b91af">SPNavigationNode</span>(<span style="color: #a31515">&quot;Modify Widget Settings&quot;</span>,
                    <span style="color: #2b91af">SPUrlUtility</span>.CombineUrl(site.Url, <span style="color: #a31515">&quot;DevExpertise.LayoutsApp/WidgetSettings.aspx&quot;</span>), <span style="color: blue">true</span>);

                <span style="color: green">// add the Widget management node to the menu (must be done first)
                </span>site.Navigation.QuickLaunch.AddAsLast(widgetManagementNode);

                <span style="color: green">// add the sub-items to the Widget Management node
                </span>widgetManagementNode.Children.AddAsLast(viewWidgetsNode);
                widgetManagementNode.Children.AddAsLast(addWidgetNode);
                widgetManagementNode.Children.AddAsLast(widgetSettingsNode);

                <span style="color: green">// update the site
                </span>site.Update();
            }
        }

        <span style="color: blue">public override void </span>FeatureDeactivating(<span style="color: #2b91af">SPFeatureReceiverProperties </span>properties) {
            <span style="color: green">// do nothing
        </span>}

        <span style="color: blue">public override void </span>FeatureInstalled(<span style="color: #2b91af">SPFeatureReceiverProperties </span>properties) {
            <span style="color: green">// do nothing
        </span>}

        <span style="color: blue">public override void </span>FeatureUninstalling(<span style="color: #2b91af">SPFeatureReceiverProperties </span>properties) {
            <span style="color: green">// do nothing
        </span>}
    }
}</pre>
</div>
<p>
  <br />As you can see, it’s not complicated at all.&#160; Simply add as many <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.navigation.spnavigationnode.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">SPNavigationNodes</a> as you like!&#160; The next step is to tell the feature to execute the custom feature receiver.&#160; For that just add the ReceiverAssembly and ReceiverClass elements to your feature definition file:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot; <span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">utf-8</span>&quot;<span style="color: blue">?&gt;
&lt;</span><span style="color: #a31515">Feature
  </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">5856617E-BED2-4705-B030-735F7483225E</span>&quot;
  <span style="color: red">Title</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise Layouts Application</span>&quot;
  <span style="color: red">Description</span><span style="color: blue">=</span>&quot;<span style="color: blue">Contains the necessary components for the DevExpertise custom LAYOUTS application.</span>&quot;
  <span style="color: red">Version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0.0.0</span>&quot;
  <span style="color: red">Scope</span><span style="color: blue">=</span>&quot;<span style="color: blue">Web</span>&quot;
  <span style="color: red">Hidden</span><span style="color: blue">=</span>&quot;<span style="color: blue">false</span>&quot;
  <span style="color: red">ImageUrl</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise\devexpertiseLogo.png</span>&quot;
  <span style="color: red">ReceiverAssembly</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise.LayoutsApp, Version=1.0.0.0, culture=neutral, PublicKeyToken=d39eedb6cff9b1c8</span>&quot;
  <span style="color: red">ReceiverClass</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise.LayoutsApp.FeatureReceiver</span>&quot;
  <span style="color: red">xmlns</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://schemas.microsoft.com/sharepoint/</span>&quot;<span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">Feature</span><span style="color: blue">&gt;</span></pre>
</div>
<p>
  <br />Once the feature is properly installed, it will show up under Site Features (note that this is scoped at the site level, and will need to be activated on each site):</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/image.png"  rel="lightbox"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="66" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/03/image-thumb.png" width="719" border="0" /></a> </p>
<p>
  <br />Cross your fingers, activate it, and you should the new navigation items:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/image1.png"  rel="lightbox"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="347" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/03/image-thumb1.png" width="143" border="0" /></a></p>
<p>
  <br />Not too shabby for a few lines of code, huh?&#160; You’re just as able to add items to the top navigation if you so desire too.&#160; </p>
<p>
  <br /><strong>Approach #2: Custom Actions<br />
    <br /></strong>One of my favorite things about SharePoint is the ability to extend just about anything, making it a true application development.&#160; Menu items are no exception, and they’re painfully simple to implement.&#160; You are able to add a custom link to the Site Actions menu, Site Settings menus, list menus, individual item menus, Central Administration menus, etc.&#160; If SharePoint has a menu somewhere, chances are you’re able to add your own item to it.&#160; There are 2 ways to do this and I’ll only be demonstrating it one way.&#160; In a future blog post I’ll show how to do all this stuff programmatically for an even more robust navigation structure.</p>
<p>For this sample Widgets application, I would like to take the navigation a bit further and add an item to the Site Actions menu and also create a group in Site Settings that will allow me to manage my application.&#160; To accomplish this, I added a new element manifest to my feature called CustomActions.xml, which will define our custom actions.&#160; Per MSDN, custom action files are included as part of a feature and deployed as XML element descriptions, and structured with a <a href="http://msdn.microsoft.com/en-us/library/ms460194.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">CustomAction</a> element, which serves as the core definition for a single action of a link or toolbar item. The following is my CustomActions.xml file, which defines a single action for the Site Actions menu:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot; <span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">utf-8</span>&quot; <span style="color: blue">?&gt;
&lt;</span><span style="color: #a31515">Elements </span><span style="color: red">xmlns</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://schemas.microsoft.com/sharepoint/</span>&quot;<span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">CustomAction
    </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">ManageWidgetAction</span>&quot;
    <span style="color: red">GroupId</span><span style="color: blue">=</span>&quot;<span style="color: blue">SiteActions</span>&quot;
    <span style="color: red">Location</span><span style="color: blue">=</span>&quot;<span style="color: blue">Microsoft.SharePoint.StandardMenu</span>&quot;
    <span style="color: red">Sequence</span><span style="color: blue">=</span>&quot;<span style="color: blue">1</span>&quot;
    <span style="color: red">Title</span><span style="color: blue">=</span>&quot;<span style="color: blue">Manage Widgets</span>&quot;
    <span style="color: red">Description</span><span style="color: blue">=</span>&quot;<span style="color: blue">Manage your company's widget catalog.</span>&quot;
    <span style="color: red">ImageUrl </span><span style="color: blue">=</span>&quot;<span style="color: blue">/_layouts/images/actionssettings.gif</span>&quot;
    <span style="color: red">Rights</span><span style="color: blue">=</span>&quot;<span style="color: blue">ManageWeb,ManageLists</span>&quot;<span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">UrlAction </span><span style="color: red">Url</span><span style="color: blue">=</span>&quot;<span style="color: blue">~site/_layouts/DevExpertise.LayoutsApp/ManageWidgets.aspx</span>&quot; <span style="color: blue">/&gt;
  &lt;/</span><span style="color: #a31515">CustomAction</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">Elements</span><span style="color: blue">&gt;
</span></pre>
</div>
<p>
  <br />Let’s break this down a little bit:</p>
<ul>
<li><strong>Id</strong>.&#160; The ID of your custom action. </li>
<li><strong>GroupId</strong>. A pre-defined or custom that determines what group it will be placed into.&#160; A comprehensive list of built-in values can be found <a href="http://msdn.microsoft.com/en-us/library/bb802730.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">here</a>. </li>
<li><strong>Location</strong>.&#160; The location at which your custom action will be applied.&#160; A comprehensive list of built-in values can be found <a href="http://msdn.microsoft.com/en-us/library/bb802730.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">here</a>. </li>
<li><strong>Sequence</strong>.&#160; The order in which your custom action will appear in relation to other custom actions. </li>
<li><strong>Title</strong>.&#160; The display title of the action. </li>
<li><strong>Description</strong>.&#160; The description of the action, if applicable. </li>
<li><strong>ImageUrl</strong>. The image that is displayed next to the action, if applicable. </li>
<li><strong>Rights</strong>.&#160; A comma delimited list of <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">SPBasePermission</a> enumeration items.&#160; A comprehensive list of values can be found <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">here</a>. </li>
<li><strong>RequireSiteAdministrator</strong>.&#160; A true/false value indicating if this option is only visible to the site collection administrator. </li>
<li>UrlAction: This element defines where the link will take you.&#160; Be sure to specify either the ~site or ~sitecollection token which tells SharePoint to build the URL relative to either the site or site collection, respectively. </li>
</ul>
<p>Simply modify the feature to include this element manifest, redeploy it, reactivate it, and you should see the following in your Site Actions menu:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/image2.png"  rel="lightbox"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="200" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/03/image-thumb2.png" width="253" border="0" /></a></p>
<p>
  <br />Easy, huh?&#160; Let’s take this a step further and add a few items to the Site Setting page.&#160; You can either add items to existing groups on that page, or create your own.&#160; I created my own by specifying CustomActionGroup in my CustomActions.xml file, as well as a few CustomAction elements that will be a part of my custom group.&#160; The XML is fairly straightforward:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">CustomActionGroup
  </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">LayoutsAppCustomActionGroup</span>&quot;
  <span style="color: red">Title</span><span style="color: blue">=</span>&quot;<span style="color: blue">Widget Application Settings</span>&quot;
  <span style="color: red">Sequence</span><span style="color: blue">=</span>&quot;<span style="color: blue">1</span>&quot;
  <span style="color: red">Location</span><span style="color: blue">=</span>&quot;<span style="color: blue">Microsoft.SharePoint.SiteSettings</span>&quot;<span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">CustomActionGroup</span><span style="color: blue">&gt;

&lt;</span><span style="color: #a31515">CustomAction
  </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">UserGroupAdminLinkForSettings</span>&quot;
  <span style="color: red">GroupId</span><span style="color: blue">=</span>&quot;<span style="color: blue">LayoutsAppCustomActionGroup</span>&quot;
  <span style="color: red">Location</span><span style="color: blue">=</span>&quot;<span style="color: blue">Microsoft.SharePoint.SiteSettings</span>&quot;
  <span style="color: red">Rights</span><span style="color: blue">=</span>&quot;<span style="color: blue">ManageWeb,ManageLists</span>&quot;
  <span style="color: red">Sequence</span><span style="color: blue">=</span>&quot;<span style="color: blue">1</span>&quot;
  <span style="color: red">Title</span><span style="color: blue">=</span>&quot;<span style="color: blue">Manage Widget Categories</span>&quot;<span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">UrlAction </span><span style="color: red">Url</span><span style="color: blue">=</span>&quot;<span style="color: blue">~site/_layouts/DevExpertise.LayoutsApp/Categories.aspx</span>&quot; <span style="color: blue">/&gt;
&lt;/</span><span style="color: #a31515">CustomAction</span><span style="color: blue">&gt;

&lt;</span><span style="color: #a31515">CustomAction
  </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">UserGroupAdminLinkForSettings</span>&quot;
  <span style="color: red">GroupId</span><span style="color: blue">=</span>&quot;<span style="color: blue">LayoutsAppCustomActionGroup</span>&quot;
  <span style="color: red">Location</span><span style="color: blue">=</span>&quot;<span style="color: blue">Microsoft.SharePoint.SiteSettings</span>&quot;
  <span style="color: red">RequireSiteAdministrator</span><span style="color: blue">=</span>&quot;<span style="color: blue">TRUE</span>&quot;
  <span style="color: red">Sequence</span><span style="color: blue">=</span>&quot;<span style="color: blue">2</span>&quot;
  <span style="color: red">Title</span><span style="color: blue">=</span>&quot;<span style="color: blue">Modify Widget Permissions</span>&quot;<span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">UrlAction </span><span style="color: red">Url</span><span style="color: blue">=</span>&quot;<span style="color: blue">~site/_layouts/DevExpertise.LayoutsApp/Permissions.aspx</span>&quot; <span style="color: blue">/&gt;
&lt;/</span><span style="color: #a31515">CustomAction</span><span style="color: blue">&gt;</span></pre>
</div>
<p>
  <br />The only notable thing to point out here is for the CustomAction elements, the GroupId is that of the CustomActionGroup I specified first.&#160; This tells SharePoint to put these actions in the custom group.&#160; Redeploy and reactivate your feature, and you will now have this in your Site Settings page:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/image3.png"  rel="lightbox"><img title="image" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="424" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/03/image-thumb3.png" width="838" border="0" /></a> </p>
<p>
  <br />Hopefully you can see from this post that it’s pretty easy to build navigation for your custom application and have that created when your application is deployed via a custom feature.&#160; In the next and final post in this series, I will show my approach to packaging everything up into features and solution packages, and how to deploy that to SharePoint in a simple and streamlined fashion.&#160; Stay tuned!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/03/04/integrating-a-custom-aspnet-application-into-sharepoint-part-3/feed/</wfw:commentRss>
		<slash:comments>10</slash:comments>
		</item>
		<item>
		<title>Integrating a Custom ASP.NET Application into SharePoint (Part 2)</title>
		<link>http://www.devexpertise.com/2009/02/25/integrating-a-custom-aspnet-application-into-sharepoint-part-2/</link>
		<comments>http://www.devexpertise.com/2009/02/25/integrating-a-custom-aspnet-application-into-sharepoint-part-2/#comments</comments>
		<pubDate>Thu, 26 Feb 2009 03:18:55 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Object Model]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint UI]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/02/25/integrating-a-custom-aspnet-application-into-sharepoint-part-2/</guid>
		<description><![CDATA[In my last post, I began describing how to integrate a custom ASP.NET application into SharePoint.&#160; SharePoint is a fantastic platform for building applications, and being able to create your own pages and application structure is a huge win when you need to add missing functionality, or to integrate a non-SharePoint application into SharePoint. My [...]]]></description>
			<content:encoded><![CDATA[<p>In my last post, I began describing how to integrate a custom ASP.NET application into SharePoint.&#160; SharePoint is a fantastic platform for building applications, and being able to create your own pages and application structure is a huge win when you need to add missing functionality, or to integrate a non-SharePoint application into SharePoint. </p>
<p>My previous post covered the basics – where to place your custom artifacts, how to inherit the master page and navigation, and how the custom application runs in the context specified in the URL.&#160; This post will briefly cover securing your application pages and will also cover some useful design and UI techniques to give your application a truly integrated look and feel.</p>
<p>If you took at a look at the code I provided, you may have noticed that my custom base class that sets the master page is inheriting from LayoutsPageBase.&#160; This is a page in the object model that is specifically meant to be inherited, and provides us the means to check the users’ rights.&#160; Since <a href="http://community.bamboosolutions.com/members/Nat/default.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/community.bamboosolutions.com');" target="_blank">Natnael Gebremariam</a> of Bamboo Solutions already did a fantastic job of explaining this and some of the nuances <a href="http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2008/10/15/secure-a-sharepoint-application-page.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/community.bamboosolutions.com');" target="_blank">in his post here</a>, I will skip that and just provide a high-level overview.&#160; Basically there are 3 properties that can be overridden to customize the required permissions for your page:</p>
<ul>
<li><strong>AllowAnonymousAccess</strong>: A boolean value indicating if the page is accessible by anonymous users. </li>
<li><strong>RequireSiteAdministrator</strong>: A boolean value indicating if the page is <em>only </em>accessible by site collection administrators. </li>
<li><strong>RightsRequired</strong>: A list of <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.spbasepermissions.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank">SPBasePermissions</a> that specify the granular permissions that are necessary to access the page. </li>
</ul>
<p>For the purposes of this blog series I kept it simple, and I’m denying anonymous access, not requiring users to be site collection administrators, but requiring the user to have at least ManageLists and ManageWeb permissions:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">protected override bool </span>AllowAnonymousAccess {
    <span style="color: blue">get </span>{
        <span style="color: blue">return false</span>;
    }
}

<span style="color: blue">protected override bool </span>RequireSiteAdministrator {
    <span style="color: blue">get </span>{
        <span style="color: green">// only allow site collection administrators access?
        </span><span style="color: blue">return false</span>;
    }
}

<span style="color: blue">protected override </span><span style="color: #2b91af">SPBasePermissions </span>RightsRequired {
    <span style="color: blue">get </span>{
        <span style="color: #2b91af">SPBasePermissions </span>permissions = <span style="color: blue">base</span>.RightsRequired
            | <span style="color: #2b91af">SPBasePermissions</span>.ManageLists
            | <span style="color: #2b91af">SPBasePermissions</span>.ManageWeb;

        <span style="color: blue">return </span>permissions;
    }
}</pre>
</div>
<p>What I don’t particularly like is only being able to specify the permissions that are available through SharePoint, and not being able to specify my own. What if I wanted to check against Active Directory, or the users’ presence in a group, or validate against a line-of-business application?&#160; It’s not built-in, but Natnael describes a pretty good approach that will allow you to accomplish this.</p>
<p>Alright, now that I have the security in place, I can begin building the application.&#160; I’m going to pretend this application is a front-end to a line-of-business database that manages my Widget inventory.&#160; The focus of the rest of this post is going to be on utilizing some out-of-the-box SharePoint web controls.&#160; Don’t pay <em>too</em> much attention to the implementation of these, as this will serve as an overview of some of the server and user controls that you can leverage.&#160; In future posts I’ll elaborate a little on some of these and provide the nitty-gritty details, but for the sake of brevity I’ll just be covering the basics here.</p>
<p>First, we need to register the controls that we are going to use at the top of the ASPX pages.&#160; This is not a comprehensive list, but should give you the idea:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="background: #ffee62">&lt;%</span><span style="color: blue">@ </span><span style="color: #a31515">Register </span><span style="color: red">TagPrefix</span><span style="color: blue">=&quot;wssuc&quot; </span><span style="color: red">TagName</span><span style="color: blue">=&quot;InputFormSection&quot; </span><span style="color: red">Src</span><span style="color: blue">=&quot;/_controltemplates/InputFormSection.ascx&quot; </span><span style="background: #ffee62">%&gt;
&lt;%</span><span style="color: blue">@ </span><span style="color: #a31515">Register </span><span style="color: red">TagPrefix</span><span style="color: blue">=&quot;wssuc&quot; </span><span style="color: red">TagName</span><span style="color: blue">=&quot;InputFormControl&quot; </span><span style="color: red">Src</span><span style="color: blue">=&quot;/_controltemplates/InputFormControl.ascx&quot; </span><span style="background: #ffee62">%&gt;
&lt;%</span><span style="color: blue">@ </span><span style="color: #a31515">Register </span><span style="color: red">TagPrefix</span><span style="color: blue">=&quot;wssuc&quot; </span><span style="color: red">TagName</span><span style="color: blue">=&quot;ButtonSection&quot; </span><span style="color: red">Src</span><span style="color: blue">=&quot;/_controltemplates/ButtonSection.ascx&quot; </span><span style="background: #ffee62">%&gt;
&lt;%</span><span style="color: blue">@ </span><span style="color: #a31515">Register </span><span style="color: red">TagPrefix</span><span style="color: blue">=&quot;wssuc&quot; </span><span style="color: red">TagName</span><span style="color: blue">=&quot;ToolBar&quot; </span><span style="color: red">Src</span><span style="color: blue">=&quot;/_controltemplates/ToolBar.ascx&quot; </span><span style="background: #ffee62">%&gt;
&lt;%</span><span style="color: blue">@ </span><span style="color: #a31515">Register </span><span style="color: red">TagPrefix</span><span style="color: blue">=&quot;wssuc&quot; </span><span style="color: red">TagName</span><span style="color: blue">=&quot;ToolBarButton&quot; </span><span style="color: red">Src</span><span style="color: blue">=&quot;/_controltemplates/ToolBarButton.ascx&quot; </span><span style="background: #ffee62">%&gt;
&lt;%</span><span style="color: blue">@ </span><span style="color: #a31515">Register </span><span style="color: red">TagPrefix</span><span style="color: blue">=&quot;SharePoint&quot; </span><span style="color: red">Namespace</span><span style="color: blue">=&quot;Microsoft.SharePoint.WebControls&quot;
    </span><span style="color: red">Assembly</span><span style="color: blue">=&quot;Microsoft.SharePoint, Version=12.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c&quot; </span><span style="background: #ffee62">%&gt;</span></pre>
</div>
<p>
  <br /><strong>Toolbar/SPToolBarButton<br />
    <br /></strong>Many applications have a need for a toolbar, and even SharePoint is littered with them.&#160; You’re able to build one of your own by using the Toolbar.ascx user control (inside the CONTROLTEMPLATES folder), and the <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.sptoolbarbutton.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank">SPToolBarButton</a> controls (found within the Microsoft.SharePoint.WebControls namespace):</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">wssuc</span><span style="color: blue">:</span><span style="color: #a31515">Toolbar </span><span style="color: red">id</span><span style="color: blue">=&quot;tb&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;&gt;
    &lt;</span><span style="color: #a31515">Template_Buttons</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">SharePoint</span><span style="color: blue">:</span><span style="color: #a31515">SPToolBarButton
            </span><span style="color: red">ID</span><span style="color: blue">=&quot;btnAdd&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Add Widget&quot;
            </span><span style="color: red">ImageUrl</span><span style="color: blue">=&quot;Images/add.gif&quot; </span><span style="color: red">NavigateUrl</span><span style="color: blue">=&quot;AddWidget.aspx&quot; /&gt;
        &lt;</span><span style="color: #a31515">SharePoint</span><span style="color: blue">:</span><span style="color: #a31515">SPToolBarButton
            </span><span style="color: red">ID</span><span style="color: blue">=&quot;btnRefresh&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Refresh List&quot;
            </span><span style="color: red">ImageUrl</span><span style="color: blue">=&quot;Images/refresh1.ico&quot; </span><span style="color: red">OnClick</span><span style="color: blue">=&quot;btnRefresh_Click&quot; /&gt;
    &lt;/</span><span style="color: #a31515">Template_Buttons</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">Template_RightButtons</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">SharePoint</span><span style="color: blue">:</span><span style="color: #a31515">SPToolBarButton
            </span><span style="color: red">ID</span><span style="color: blue">=&quot;btnHelp&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Help&quot;
            </span><span style="color: red">ImageUrl</span><span style="color: blue">=&quot;Images/help.gif&quot; </span><span style="color: red">NavigateUrl</span><span style="color: blue">=&quot;Help.aspx&quot;  /&gt;
    &lt;/</span><span style="color: #a31515">Template_RightButtons</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">wssuc</span><span style="color: blue">:</span><span style="color: #a31515">Toolbar</span><span style="color: blue">&gt;</span></pre>
</div>
<p>
  <br />The above markup will render: </p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image56.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="24" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb54.png" width="537" border="0" /></a>&#160; </p>
<p><strong>SPGridView<br />
    <br /></strong>The next control worth mentioning is the all-powerful <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.spgridview.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank">SPGridView</a> control.&#160; This control is inherited from the ASP.NET GridView control which is already a great control, but the SPGridView provides a ton more functionality.&#160; In supports grouping, it automatically inherits the styles of SharePoint, and you are able to add drop-down menus to your items, like users are already used to in lists and libraries.&#160; The markup syntax is pretty straightforward:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">SharePoint</span><span style="color: blue">:</span><span style="color: #a31515">SPGridView
    </span><span style="color: red">ID</span><span style="color: blue">=&quot;grid&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">AutoGenerateColumns</span><span style="color: blue">=&quot;false&quot; </span><span style="color: red">AllowSorting</span><span style="color: blue">=&quot;true&quot;
    </span><span style="color: red">AllowGrouping</span><span style="color: blue">=&quot;true&quot; </span><span style="color: red">GroupField</span><span style="color: blue">=&quot;Category&quot; </span><span style="color: red">AllowGroupCollapse</span><span style="color: blue">=&quot;true&quot;&gt;

    &lt;</span><span style="color: #a31515">Columns</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">BoundField </span><span style="color: red">HeaderText</span><span style="color: blue">=&quot;ID&quot; </span><span style="color: red">DataField</span><span style="color: blue">=&quot;ID&quot; </span><span style="color: red">SortExpression</span><span style="color: blue">=&quot;ID&quot; /&gt;
         &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">BoundField
            </span><span style="color: red">HeaderText</span><span style="color: blue">=&quot;Name&quot; </span><span style="color: red">DataField</span><span style="color: blue">=&quot;Name&quot;
            </span><span style="color: red">SortExpression</span><span style="color: blue">=&quot;Name&quot; /&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">BoundField
            </span><span style="color: red">HeaderText</span><span style="color: blue">=&quot;Price&quot; </span><span style="color: red">DataField</span><span style="color: blue">=&quot;Price&quot;
            </span><span style="color: red">SortExpression</span><span style="color: blue">=&quot;Price&quot; /&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">BoundField
            </span><span style="color: red">HeaderText</span><span style="color: blue">=&quot;Quantity on Hand&quot; </span><span style="color: red">DataField</span><span style="color: blue">=&quot;QuantityOnHand&quot;
            </span><span style="color: red">SortExpression</span><span style="color: blue">=&quot;QuantityOnHand&quot; /&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">BoundField
            </span><span style="color: red">HeaderText</span><span style="color: blue">=&quot;Date Added&quot; </span><span style="color: red">DataField</span><span style="color: blue">=&quot;DateAdded&quot;
            </span><span style="color: red">SortExpression</span><span style="color: blue">=&quot;DateAdded&quot; /&gt;
    &lt;/</span><span style="color: #a31515">Columns</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">SharePoint</span><span style="color: blue">:</span><span style="color: #a31515">SPGridView</span><span style="color: blue">&gt;</span></pre>
</div>
<p>
  <br />The above markup will render </p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image57.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="329" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb55.png" width="588" border="0" /></a> </p>
<p>Let’s take this a step further and add the familiar drop-down list to the Name column.&#160; There are a ton of examples on how to do this in code-behind, most notably <a href="http://blogs.msdn.com/powlo/default.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/blogs.msdn.com');" target="_blank">Powlo’s</a> posts <a href="http://blogs.msdn.com/powlo/archive/2007/02/25/displaying-custom-data-through-sharepoint-lists-using-spgridview-and-spmenufield.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/blogs.msdn.com');" target="_blank">here</a> and <a href="http://blogs.msdn.com/powlo/archive/2007/03/23/Adding-paging-to-SPGridView-when-using-custom-data-sources.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/blogs.msdn.com');" target="_blank">here</a>, but here’s a little preview on how to do this in the markup.&#160; First, we need to create our <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.menutemplate.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank">MenuTemplate</a>, which defines the items in the drop-down list:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">SharePoint</span><span style="color: blue">:</span><span style="color: #a31515">MenuTemplate </span><span style="color: red">ID</span><span style="color: blue">=&quot;menuTemplate&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;&gt;
    &lt;</span><span style="color: #a31515">SharePoint</span><span style="color: blue">:</span><span style="color: #a31515">MenuItemTemplate </span><span style="color: red">ID</span><span style="color: blue">=&quot;menuEdit&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;
        </span><span style="color: red">Text</span><span style="color: blue">=&quot;Edit Widget&quot; </span><span style="color: red">ImageUrl</span><span style="color: blue">=&quot;Images/gear.gif&quot;
        </span><span style="color: red">ClientOnClickScript</span><span style="color: blue">=&quot;javascript:editSomething('%ID%');&quot; /&gt;
    &lt;</span><span style="color: #a31515">SharePoint</span><span style="color: blue">:</span><span style="color: #a31515">MenuItemTemplate </span><span style="color: red">ID</span><span style="color: blue">=&quot;menuDelete&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;
        </span><span style="color: red">Text</span><span style="color: blue">=&quot;Delete Widget&quot; </span><span style="color: red">ImageUrl</span><span style="color: blue">=&quot;Images/delete.gif&quot;
        </span><span style="color: red">ClientOnClickScript</span><span style="color: blue">=&quot;javascript:deleteSomething('%ID%');&quot; /&gt;
&lt;/</span><span style="color: #a31515">SharePoint</span><span style="color: blue">:</span><span style="color: #a31515">MenuTemplate</span><span style="color: blue">&gt;</span></pre>
</div>
<p>
  <br />Next, replace the BoundField with an <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.spmenufield.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank">SPMenuField</a>, and specify the menu this is bound to by assigning the MenuTemplateID property to the ID of the menu template we just created.&#160; The TokenNameAndValueFields property assigns a token to a field in the data source.&#160; In this example, I’m declaring two tokens, one for ID and another for Name, which can then be used elsewhere.&#160; The NavigateUrlFields specifies the fields that can be used in the URL set in the NavigateUrlFormat property, and in the same order (it works like the String.Format() method):</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">SharePoint</span><span style="color: blue">:</span><span style="color: #a31515">SPMenuField
    </span><span style="color: red">HeaderText</span><span style="color: blue">=&quot;Name&quot; </span><span style="color: red">TextFields</span><span style="color: blue">=&quot;Name&quot; </span><span style="color: red">MenuTemplateId</span><span style="color: blue">=&quot;menuTemplate&quot;
    </span><span style="color: red">TokenNameAndValueFields</span><span style="color: blue">=&quot;ID=ID,NAME=Name&quot; </span><span style="color: red">NavigateUrlFields</span><span style="color: blue">=&quot;ID&quot;
    </span><span style="color: red">NavigateUrlFormat</span><span style="color: blue">=&quot;EditWidget.aspx?id={0}&quot; /&gt; </span></pre>
</div>
<p>
  <br />The above markup will render: </p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image58.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="244" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb56.png" width="566" border="0" /></a>&#160;</p>
<p>
  <br /><strong>Form Fields</strong> </p>
<p>For creating form fields, there are a ton of ways to skin this cat, but I typically choose one of the following two approaches.&#160; Typically your data-entry forms should either look like the forms used for new list items, or the forms for new lists, sites, or pages.&#160; The simplest and arguably cleanest approach is to just use the ASP.NET controls you’re used to, such as a TextBox, DropDownList, etc., and place them in a table that have the SharePoint styles applied to them.&#160; The end result will look something like this:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image59.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="326" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb57.png" width="594" border="0" /></a> </p>
<p>The markup is pretty simple; the important part is is the style classes applied to the elements, specifically ms-formlabel, ms-formbody, and ms-input.&#160; For the sake of brevity, here is a portion of the markup for the above form:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">tr</span><span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">td </span><span style="color: red">class</span><span style="color: blue">=&quot;ms-formlabel&quot;&gt;
      </span>Date Added:
  <span style="color: blue">&lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">td </span><span style="color: red">class</span><span style="color: blue">=&quot;ms-formbody&quot;&gt;
      &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">TextBox </span><span style="color: red">id</span><span style="color: blue">=&quot;txtDateAdded&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">CssClass</span><span style="color: blue">=&quot;ms-input&quot; </span><span style="color: red">width</span><span style="color: blue">=&quot;200px&quot; /&gt;
  &lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">tr</span><span style="color: blue">&gt;
&lt;</span><span style="color: #a31515">tr</span><span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">td </span><span style="color: red">class</span><span style="color: blue">=&quot;ms-formlabel&quot;&gt;
      </span>Category:
  <span style="color: blue">&lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">td </span><span style="color: red">class</span><span style="color: blue">=&quot;ms-formbody&quot;&gt;
      &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">DropDownList </span><span style="color: red">id</span><span style="color: blue">=&quot;txtCategory&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">CssClass</span><span style="color: blue">=&quot;ms-input&quot; </span><span style="color: red">width</span><span style="color: blue">=&quot;200px&quot;&gt;
          &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">ListItem</span><span style="color: blue">&gt;</span>Cheap Widgets<span style="color: blue">&lt;/</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">ListItem</span><span style="color: blue">&gt;
          &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">ListItem</span><span style="color: blue">&gt;</span>Expensive Widgets<span style="color: blue">&lt;/</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">ListItem</span><span style="color: blue">&gt;
      &lt;/</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">DropDownList</span><span style="color: blue">&gt;
  &lt;/</span><span style="color: #a31515">td</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">tr</span><span style="color: blue">&gt;</span></pre>
</div>
<p>
  <br />The second approach is to make the form look like the new list/site pages in SharePoint.&#160; This is perfectly fine too, but takes up a little more space:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image60.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="574" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb58.png" width="594" border="0" /></a></p>
<p>The markup for this is a little more complex, and involves the use of <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.inputformsection.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank">InputFormSection</a> and <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.inputformcontrol.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank">InputFormControl</a> sections.&#160; A sample of the markup used for the above form is as follows:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">&lt;</span><span style="color: #a31515">wssuc</span><span style="color: blue">:</span><span style="color: #a31515">InputFormSection </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">Title</span><span style="color: blue">=&quot;&quot; </span><span style="color: red">id</span><span style="color: blue">=&quot;dateSection&quot;&gt;
    &lt;</span><span style="color: #a31515">template_description</span><span style="color: blue">&gt;
       &lt;</span><span style="color: #a31515">b</span><span style="color: blue">&gt;</span>Date<span style="color: blue">&lt;/</span><span style="color: #a31515">b</span><span style="color: blue">&gt;&lt;</span><span style="color: #a31515">br </span><span style="color: blue">/&gt;</span>Please specify a date.
    <span style="color: blue">&lt;/</span><span style="color: #a31515">template_description</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">template_inputformcontrols</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">wssuc</span><span style="color: blue">:</span><span style="color: #a31515">InputFormControl </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">LabelText</span><span style="color: blue">=&quot;Date:&quot;&gt;
            &lt;</span><span style="color: #a31515">Template_Control</span><span style="color: blue">&gt;
                &lt;</span><span style="color: #a31515">wssawc</span><span style="color: blue">:</span><span style="color: #a31515">DateTimeControl  </span><span style="color: red">ID</span><span style="color: blue">=&quot;txtDate&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;
                    </span><span style="color: red">DateOnly</span><span style="color: blue">=&quot;true&quot; /&gt;&lt;</span><span style="color: #a31515">BR </span><span style="color: blue">/&gt;
            &lt;/</span><span style="color: #a31515">Template_Control</span><span style="color: blue">&gt;
        &lt;/</span><span style="color: #a31515">wssuc</span><span style="color: blue">:</span><span style="color: #a31515">InputFormControl</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">template_inputformcontrols</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">wssuc</span><span style="color: blue">:</span><span style="color: #a31515">InputFormSection</span><span style="color: blue">&gt;  

&lt;</span><span style="color: #a31515">wssuc</span><span style="color: blue">:</span><span style="color: #a31515">InputFormSection </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">Title</span><span style="color: blue">=&quot;&quot; </span><span style="color: red">id</span><span style="color: blue">=&quot;categorySection&quot;&gt;
    &lt;</span><span style="color: #a31515">template_description</span><span style="color: blue">&gt;
       &lt;</span><span style="color: #a31515">b</span><span style="color: blue">&gt;</span>Category<span style="color: blue">&lt;/</span><span style="color: #a31515">b</span><span style="color: blue">&gt;&lt;</span><span style="color: #a31515">br </span><span style="color: blue">/&gt;</span>Please specify a category
    <span style="color: blue">&lt;/</span><span style="color: #a31515">template_description</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">template_inputformcontrols</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">wssuc</span><span style="color: blue">:</span><span style="color: #a31515">InputFormControl </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">LabelText</span><span style="color: blue">=&quot;Category:&quot;&gt;
            &lt;</span><span style="color: #a31515">Template_Control</span><span style="color: blue">&gt;
                &lt;</span><span style="color: #a31515">wssawc</span><span style="color: blue">:</span><span style="color: #a31515">InputFormTextBox </span><span style="color: red">ID</span><span style="color: blue">=&quot;txtCategory&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;
                    </span><span style="color: red">Columns</span><span style="color: blue">=&quot;40&quot; </span><span style="color: red">class</span><span style="color: blue">=&quot;ms-input&quot;  /&gt;&lt;</span><span style="color: #a31515">BR </span><span style="color: blue">/&gt;
            &lt;/</span><span style="color: #a31515">Template_Control</span><span style="color: blue">&gt;
        &lt;/</span><span style="color: #a31515">wssuc</span><span style="color: blue">:</span><span style="color: #a31515">InputFormControl</span><span style="color: blue">&gt;
    &lt;/</span><span style="color: #a31515">template_inputformcontrols</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">wssuc</span><span style="color: blue">:</span><span style="color: #a31515">InputFormSection</span><span style="color: blue">&gt; 

&lt;</span><span style="color: #a31515">wssuc</span><span style="color: blue">:</span><span style="color: #a31515">ButtonSection </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">ShowStandardCancelButton</span><span style="color: blue">=&quot;false&quot;&gt;
    &lt;</span><span style="color: #a31515">Template_Buttons</span><span style="color: blue">&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Button </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">class</span><span style="color: blue">=&quot;ms-ButtonHeightWidth&quot;
            </span><span style="color: red">Text</span><span style="color: blue">=&quot;Save&quot; </span><span style="color: red">id</span><span style="color: blue">=&quot;btnSave&quot; /&gt;
        &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Button </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">class</span><span style="color: blue">=&quot;ms-ButtonHeightWidth&quot;
            </span><span style="color: red">Text</span><span style="color: blue">=&quot;Cancel&quot; </span><span style="color: red">id</span><span style="color: blue">=&quot;btnCancel&quot; </span><span style="color: red">CausesValidation</span><span style="color: blue">=&quot;false&quot; /&gt;
    &lt;/</span><span style="color: #a31515">Template_Buttons</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">wssuc</span><span style="color: blue">:</span><span style="color: #a31515">ButtonSection</span><span style="color: blue">&gt;</span></pre>
</div>
</p>
</p>
</p>
</p>
</p>
</p>
<p>
  <br />As you can see, it’s lot more code, but you’re given a few extra things to work with, like the label and label description to the left, and the extra space to the right.&#160; You’ll also notice I’m using built-in SharePoint controls for the textboxes and the date picker.&#160; There are a bunch of controls that you can leverage, many of which I’ll cover in a future post.&#160; If you’re ambitious though, feel free to poke around the assembly with Reflector or the Object Browser in Visual Studio.&#160; Here’s a screenshot of what you’ll find:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image61.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="432" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb59.png" width="533" border="0" /></a> </p>
<p>There’s all kinds of goodies that are available for us to use in our applications.&#160; Stay tuned for a future post that will dive into a few more of them!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/02/25/integrating-a-custom-aspnet-application-into-sharepoint-part-2/feed/</wfw:commentRss>
		<slash:comments>25</slash:comments>
		</item>
		<item>
		<title>Integrating a Custom ASP.NET Application into SharePoint (Part 1)</title>
		<link>http://www.devexpertise.com/2009/02/18/integrating-a-custom-aspnet-application-into-sharepoint-part-1/</link>
		<comments>http://www.devexpertise.com/2009/02/18/integrating-a-custom-aspnet-application-into-sharepoint-part-1/#comments</comments>
		<pubDate>Thu, 19 Feb 2009 00:01:45 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[Object Model]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint UI]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/02/18/integrating-a-custom-aspnet-application-into-sharepoint-part-1/</guid>
		<description><![CDATA[One of the great things about SharePoint is in addition to all cool stuff it does out-of-the-box, you can add on functionality.&#160; More importantly though, SharePoint can be a great platform to build your own application on top of.&#160; In this series, I will show you how to build a custom ASP.NET application and integrate [...]]]></description>
			<content:encoded><![CDATA[<p>One of the great things about SharePoint is in addition to all cool stuff it does out-of-the-box, you can add on functionality.&#160; More importantly though, SharePoint can be a great platform to build your own application on top of.&#160; In this series, I will show you how to build a custom ASP.NET application and integrate it seamlessly into SharePoint.</p>
<p>The first thing to understand is the location at which we will deploy our custom artifacts.&#160; Since the application will run under the context of a SharePoint site, the files will be deployed to the LAYOUTS folder within the ~12 directory.&#160; There isn’t a need to create a new IIS web site or virtual directory, as it’s using the SharePoint site.</p>
<p>Now, there are different opinions on where certain artifacts should go.&#160; I really don’t think it matters; just personal preference.&#160; One option is to stick with the folder structure that SharePoint uses, and just place a custom folder in each of the destinations that contain your custom artifacts.&#160; Typically this involves placing your files in the following directories: </p>
<div>
<table style="font-size: 8pt; border-collapse: collapse" width="769" border="0">
<colgroup>
<col style="width: 100px" />
<col style="width: 544px" /></colgroup>
<tbody valign="top">
<tr style="background: #dbe5f1">
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: #bfbfbf 0.5pt solid; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="151"><span style="font-size: 8pt; font-family: verdana"><strong>Type</strong></span></td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: #bfbfbf 0.5pt solid; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="325"><span style="font-size: 8pt; font-family: verdana"><strong>Destination</strong></span>&#160;</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: #bfbfbf 0.5pt solid; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="291"><b>Reference Path</b>&#160;</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="151">.aspx</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="325">12\TEMPLATE\LAYOUTS\&lt;ProjectName&gt;\</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="291">~/_layouts/&lt;ProjectName&gt;/Page.aspx</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="151">.ascx</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="325">12\TEMPLATE\CONTROLTEMPLATES\&lt;ProjectName&gt;\</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="291">~/_controltemplates/&lt;ProjectName&gt;/control.ascx</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="151">web.config</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="325">12\TEMPLATE\LAYOUTS\&lt;ProjectName&gt;\</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="291">(none)</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="151">.css</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="325">12\TEMPLATE\1033\Styles\&lt;ProjectName&gt;\</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="291">/_layouts/1033/styles/&lt;ProjectName&gt;/style.css</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="151">.js</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="325">12\TEMPLATE\LAYOUTS\1033\&lt;ProjectName&gt;\</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="291">/_layouts/1033/&lt;ProjectName&gt;/script.js</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="151">.dll</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="325">Either web app’s BIN directory or GAC</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="291">(none)</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="151">Resource DLLs</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="325">GAC</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="291">(none)</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="151">Images</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="325">12\TEMPLATE\IMAGES\&lt;ProjectName&gt;\</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="291">/_layouts/images/&lt;ProjectName&gt;/image.gif</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="151">Custom Folders</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="325">12\TEMPLATE\LAYOUTS\&lt;ProjectName&gt;\</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="291">~/_layouts/&lt;ProjectName&gt;/MyFolder/…</td>
</tr>
</tbody>
</table></div>
<p>&#160;</p>
<p>The other option (and my personal preference) is to put everything within a custom folder in the LAYOUTS directory, and only put those files that would require other changes in their respective places.&#160; For example, since a SafeControls entry is required in the web.config for user controls, it makes sense to keep your user controls within that folder.&#160; You could definitely put them inside the LAYOUTS folder with everything else, but then you’d have to create another SafeControls entry. </p>
<div>
<table style="font-size: 8pt; border-collapse: collapse" width="770" border="0">
<colgroup>
<col style="width: 100px" />
<col style="width: 544px" /></colgroup>
<tbody valign="top">
<tr style="background: #dbe5f1">
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: #bfbfbf 0.5pt solid; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="147"><span style="font-size: 8pt; font-family: verdana"><strong>Type</strong></span></td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: #bfbfbf 0.5pt solid; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="324"><span style="font-size: 8pt; font-family: verdana"><strong>Destination</strong></span>&#160;</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: #bfbfbf 0.5pt solid; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="297"><b>Reference Path</b>&#160;</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="147"><strong>.</strong>aspx</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="324">12\TEMPLATE\LAYOUTS\&lt;ProjectName&gt;\</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="297">Page.aspx</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="147">.ascx</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="324">12\TEMPLATE\CONTROLTEMPLATES\&lt;ProjectName&gt;\</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="297">~/_controltemplates/&lt;ProjectName&gt;/control.ascx</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="147">web.config</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="324">12\TEMPLATE\LAYOUTS\&lt;ProjectName&gt;\</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="297">(none)</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="147">.css</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="324">12\TEMPLATE\LAYOUTS\&lt;ProjectName&gt;\Styles\</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="297">Styles/style.css</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="147">.js</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="324">12\TEMPLATE\LAYOUTS\&lt;ProjectName&gt;\Scripts\</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="297">Scripts/script.js</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="147">.dll</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="324">Either web app’s BIN directory or GAC</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="297">(none)</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="147">Resource DLLs</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="324">GAC</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="297">(none)</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="147">Images</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="324">12\TEMPLATE\LAYOUTS\&lt;ProjectName&gt;\Images</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="297">Images/image.gif</td>
</tr>
<tr>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: #bfbfbf 0.5pt solid; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="147">Custom Folders</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="324">12\TEMPLATE\LAYOUTS\&lt;ProjectName&gt;\</td>
<td style="border-right: #bfbfbf 0.5pt solid; padding-right: 10px; border-top: medium none; padding-left: 10px; padding-bottom: 3px; border-left: medium none; padding-top: 3px; border-bottom: #bfbfbf 0.5pt solid" valign="middle" width="297">MyFolder/…</td>
</tr>
</tbody>
</table></div>
<p>&#160;</p>
<p>Now that the file locations are ironed out, let’s start getting into how to develop the pages.&#160; I will dive into utilizing built-in SharePoint controls, permissions, and some of the fancier stuff in later posts, and will focus on just getting a page to show up within SharePoint.&#160; Your approach to this may differ, but this has proven very effective for me.&#160; First, I create a new web application in Visual Studio, and create a folder structure that mimics SharePoint’s 12 directory:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image52.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="362" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb50.png" width="299" border="0" /></a> </p>
<p>You’ll notice that I have 2 web.config files – one is created when the project is created and can be used to test the project locally, and the other is the one that will be put into SharePoint.&#160; My web.config that goes into SharePoint is very simple and looks like the following.&#160; For testing purposes, I added a test application setting which we’ll retrieve shortly:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot;<span style="color: blue">?&gt;
&lt;</span><span style="color: #a31515">configuration</span><span style="color: blue">&gt;
  &lt;</span><span style="color: #a31515">system.web </span><span style="color: blue">/&gt;
  &lt;</span><span style="color: #a31515">appSettings</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">add </span><span style="color: red">key</span><span style="color: blue">=</span>&quot;<span style="color: blue">customKey</span>&quot; <span style="color: red">value</span><span style="color: blue">=</span>&quot;<span style="color: blue">Sample Value</span>&quot; <span style="color: blue">/&gt;
  &lt;/</span><span style="color: #a31515">appSettings</span><span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">configuration</span><span style="color: blue">&gt;</span></pre>
</div>
<p>
  <br />The next part is probably the most important part of this whole process – setting up the ASPX markup correctly.&#160; Since this page will be integrated into SharePoint’s master page, the same master page/content page principles apply.&#160; The master page contains content place holders which define where page content will go, and the pages themselves define the content that gets inserted in these areas.&#160; SharePoint master pages have a ton of content place holders, most of which we don’t need in a custom application.&#160; The ones that are important are:</p>
<ul>
<li><strong>PlaceHolderAdditionalPageHead</strong>: The content area where custom scripts and styles will be referenced. </li>
<li><strong>PlaceHolderPageTitle</strong>: The title of the page. </li>
<li><strong>PlaceHolderPageTitleInTitleArea</strong>: The text that shows up right above the main content area. </li>
<li><strong>PlaceHolderMain</strong>: The main content area. </li>
<li><strong>PlaceHolderLeftNavBar</strong>: If you want to define your own QuickLaunch or left navigation, you could place it here. </li>
</ul>
<p>Since it’s up to us to define the content within these place holders, all we need to do is add content areas to our ASPX page and put in what we want.&#160; I only used the top 4 aforementioned areas, as I want to utilize the existing quick launch navigation menu:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="background: #ffee62">&lt;%</span><span style="color: blue">@ </span><span style="color: #a31515">Page </span><span style="color: red">Language</span><span style="color: blue">=&quot;C#&quot; </span><span style="color: red">AutoEventWireup</span><span style="color: blue">=&quot;true&quot; </span><span style="color: red">CodeBehind</span><span style="color: blue">=&quot;Home.aspx.cs&quot;
         </span><span style="color: red">Inherits</span><span style="color: blue">=&quot;DevExpertise.LayoutsApp.Home, DevExpertise.LayoutsApp,
                   Version=1.0.0.0, Culture=neutral, PublicKeyToken=d39eedb6cff9b1c8&quot; </span><span style="background: #ffee62">%&gt;

</span><span style="color: blue">&lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Content </span><span style="color: red">contentplaceholderid</span><span style="color: blue">=&quot;PlaceHolderAdditionalPageHead&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;&gt;
    &lt;</span><span style="color: #a31515">link </span><span style="color: red">rel</span><span style="color: blue">=&quot;Stylesheet&quot; </span><span style="color: red">type</span><span style="color: blue">=&quot;text/css&quot; </span><span style="color: red">href</span><span style="color: blue">=&quot;Styles/style.css&quot; /&gt;
    &lt;</span><span style="color: #a31515">script </span><span style="color: red">src</span><span style="color: blue">=&quot;Scripts/script.js&quot; </span><span style="color: red">type</span><span style="color: blue">=&quot;text/javascript&quot; /&gt;
&lt;/</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Content</span><span style="color: blue">&gt;

&lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Content </span><span style="color: red">ContentPlaceHolderID</span><span style="color: blue">=&quot;PlaceHolderPageTitle&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;Server&quot;&gt;
    </span>Page Title - Custom Application
<span style="color: blue">&lt;/</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Content</span><span style="color: blue">&gt;

&lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Content </span><span style="color: red">ContentPlaceHolderID</span><span style="color: blue">=&quot;PlaceHolderPageTitleInTitleArea&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;&gt;
    </span>Title Area - Custom Application
<span style="color: blue">&lt;/</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Content</span><span style="color: blue">&gt;

&lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Content </span><span style="color: red">ContentPlaceHolderID</span><span style="color: blue">=&quot;PlaceHolderMain&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot;&gt;
    &lt;</span><span style="color: #a31515">h1</span><span style="color: blue">&gt;</span>This is a custom application!<span style="color: blue">&lt;/</span><span style="color: #a31515">h1</span><span style="color: blue">&gt;
    &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">TextBox </span><span style="color: red">id</span><span style="color: blue">=&quot;txtValue&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; /&gt;
    &lt;</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Button </span><span style="color: red">id</span><span style="color: blue">=&quot;btnSetValue&quot; </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">Text</span><span style="color: blue">=&quot;Click Me!&quot; </span><span style="color: red">OnClick</span><span style="color: blue">=&quot;btnSetValue_Click&quot; /&gt;
&lt;/</span><span style="color: #a31515">asp</span><span style="color: blue">:</span><span style="color: #a31515">Content</span><span style="color: blue">&gt;</span></pre>
</div>
<p>
  <br />This doesn’t do much, but will prove the concept.&#160; You can see that I added a custom style sheet (style.css), and also a custom script file (script.js), just so you could see where they go.&#160; In addition, I added a textbox and a button and attached an event handler for the Click event of that button.&#160; In this event handler, I’ll retrieve the web.config setting I mentioned above and set the textbox to this value. The code-behind for this page looks like the following:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">namespace </span>DevExpertise.LayoutsApp {
    <span style="color: blue">public partial class </span><span style="color: #2b91af">Home </span>:System.Web.UI.<span style="color: #2b91af">Page  </span>{

        <span style="color: blue">protected void </span>Page_Load(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e) {
        }

        <span style="color: blue">protected void </span>btnSetValue_Click(<span style="color: blue">object </span>sender, <span style="color: #2b91af">EventArgs </span>e) {
            txtValue.Text = <span style="color: #2b91af">WebConfigurationManager</span>.AppSettings[<span style="color: #a31515">&quot;customKey&quot;</span>].ToString();
        }
    }
}</pre>
</div>
<p>&#160; <br />Since this code will be executed under the context of SharePoint, the same code access security restrictions apply here as with web parts and custom web services.&#160; You basically have 3 options: adding the assembly to the web application’s BIN directory and setting the trust level to at least WSS_Medium in the web.config, creating a custom code access security policy for your application, or adding the assembly to the GAC.&#160; There are plenty of resources regarding the advantages and disadvantages to each approach out there so I’ll spare you here.&#160; For the sake of simplicity, I added the assembly to the GAC.</p>
<p>Next, I deployed my files to the SharePoint 12 directory.&#160; Since I’m doing this in a development/test environment, I created a handy copy.bat script that uses XCOPY to copy the files to the respective directories.&#160; As soon as this project is ready to be deployed, I’ll run my solution through WSPBuilder and will generate a deployable solution package (.WSP).</p>
<p>After the files are deployed, it’s as simple as typing in the correct URL.&#160; The syntax for this is as follows:</p>
<blockquote>
<p>http://server/site/_layouts/&lt;ProjectFolder&gt;/&lt;PageName&gt;.aspx</p>
</blockquote>
<p>The URL is extremely important when accessing your application pages, as your application <strong>runs under the context of the SharePoint site specified in the URL</strong>.&#160; What does this mean?&#160; Well, if you access your page at <em>http://server/_layouts/MyProject/MyPage.aspx</em>, then it’s running under the context of the site collection’s root site, and accessing SPContext.Current.Web will return that site.&#160; If you access your page at <em>http://server/sites/it/blog/_layouts/MyProject/MyPage.aspx</em>, then it’s running under the context of the blog site under the IT site collection, and SPContext.Current.Web will reflect that.&#160; Why is this important?&#160; Well, since the application pages live in the 12 directory on the farm, they’re globally accessible, and not limited to a single site collection or site.&#160; You could even get to your application at <em>http://CentralAdminUrl/_layouts/MyProject/MyPage.aspx</em>, and it will be running under Central Administration’s context.&#160; Now do you see the importance?&#160; I will show you in a later post how to implement safeguards to mitigate this, but be aware for now that your pages are out there for everyone to access.</p>
<p>For my development machine, I will be accessing this at the following URL:</p>
<blockquote>
<p>http://server/sites/devexpertise/_layouts/DevExpertise.LayoutsApp/Home.aspx</p>
</blockquote>
<p>However, when I try to access this, I get the following:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image53.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="474" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb51.png" width="798" border="0" /></a> </p>
<p>
  <br />No worries &#8212; all this is telling me is that we forgot to specify the master page.&#160; Since this will “inherit” the master page and styles of whichever site it’s accessed from, we must set the master page to that of the current site.&#160; To accomplish this easily for each of my application pages, I create a base LayoutsAppPage that sets the master page:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">namespace </span>DevExpertise.LayoutsApp {
    <span style="color: blue">public class </span><span style="color: #2b91af">LayoutsAppPage </span>: Microsoft.SharePoint.WebControls.<span style="color: #2b91af">LayoutsPageBase </span>{

        <span style="color: blue">protected override void </span>OnPreInit(<span style="color: #2b91af">EventArgs </span>e) {
            <span style="color: blue">base</span>.OnPreInit(e);

            <span style="color: blue">try </span>{
                <span style="color: blue">this</span>.MasterPageFile = <span style="color: #2b91af">SPContext</span>.Current.Web.MasterUrl;
            }
            <span style="color: blue">catch </span>{ }
        }
    }
}</pre>
</div>
</p>
<p>
  <br />You’ll notice that I’m inheriting this from <a href="http://msdn.microsoft.com/en-us/library/microsoft.sharepoint.webcontrols.layoutspagebase.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank">LayoutsPageBase</a> – this is a base class defined in the Microsoft.SharePoint.WebControls namespace that provides us functionality for creating these types of pages.&#160; That’s beyond the scope of this first post, but I will touch on this later in the series.&#160; Next, I inherit each of my application pages from my custom LayoutsAppPage base class:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">public partial class </span><span style="color: #2b91af">Home </span>: <span style="color: #2b91af">LayoutsAppPage </span>{

}</pre>
</div>
<p>
  <br />Now if we access the page in the browser, we should get a functioning page.&#160; Clicking the button should retrieve the application setting from the web.config as well:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image55.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="474" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb53.png" width="798" border="0" /></a> </p>
</p>
<p>
  <br />Pretty slick, huh?&#160; Stay tuned for the next posts in this series where we’ll look at how to secure our application and utilize existing SharePoint controls to provide a rich and familiar user interface.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/02/18/integrating-a-custom-aspnet-application-into-sharepoint-part-1/feed/</wfw:commentRss>
		<slash:comments>27</slash:comments>
		</item>
		<item>
		<title>Creating a Wizard-Style Browser-Enabled InfoPath Form</title>
		<link>http://www.devexpertise.com/2009/02/16/creating-a-wizard-style-browser-enabled-infopath-form/</link>
		<comments>http://www.devexpertise.com/2009/02/16/creating-a-wizard-style-browser-enabled-infopath-form/#comments</comments>
		<pubDate>Mon, 16 Feb 2009 14:34:21 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[InfoPath]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/02/16/creating-a-wizard-style-browser-enabled-infopath-form/</guid>
		<description><![CDATA[InfoPath is a great tool when you need to build simple data-entry forms.&#160; Although the tool is clearly limited when it comes to creating a rich user interface with complex controls, there are things you can do to enhance the experience if you’re creative. One of the ways various applications collect data is through the [...]]]></description>
			<content:encoded><![CDATA[<p>InfoPath is a great tool when you need to build simple data-entry forms.&#160; Although the tool is clearly limited when it comes to creating a rich user interface with complex controls, there are things you can do to enhance the experience if you’re creative.</p>
<p>One of the ways various applications collect data is through the familiar wizard-style interface.&#160; A wizard can be great if you need to collect a lot of information from user, but want to break it down into manageable chunks.&#160; At first glance, InfoPath does not support such a thing, as there isn’t a fancy wizard control like there is in ASP.NET.&#160; Luckily InfoPath allows us to create views, which provide a completely different display for the fields defined in the form.&#160; With a little code and finesse, we can successfully implement a wizard-style browser-enabled InfoPath form.&#160; The end result looks like the following:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image44.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="506" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb42.png" width="724" border="0" /></a> </p>
<p>The first thing to do is define the fields that are required in the form.&#160; For the sake of this post, I built a very simple New User Wizard with a few fields, but in the real world a wizard is better suited for collecting a lot of data:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image45.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="284" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb43.png" width="276" border="0" /></a> </p>
<p>Now that the fields are defined, a view needs to be created for each “page” of the wizard.&#160; In this case, I created 2 views in addition to the default view, and also renamed the default view to page1:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image46.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="213" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb44.png" width="276" border="0" /></a> </p>
<p>On the first page, I laid out the controls for the first page, and also included a Cancel button, Back button, and Next button.&#160; I really don’t need a Back button for the first page, but i kept it in there as a placeholder and just disabled it by adding a conditional format.&#160; In addition to the fields that the user needs to fill out, we have to perform our own data validation.&#160; The reason is the validation doesn’t fire until the form is submitted, and we need to perform incremental validation just to ensure the first page’s fields are filled out correctly.&#160; I’ll get to the code required to do this shortly, but for now I just added the errorMessage field, set the fill to transparent, removed the border, and disabled it:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image47.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="363" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb45.png" width="660" border="0" /></a> </p>
<p>Next, I created the second page of the wizard by cutting &amp; pasting the first page and adding the appropriate fields:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image48.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="362" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb46.png" width="658" border="0" /></a> </p>
<p>Finally, I created the third page of the wizard, which for this scenario is just a summary page of previously filled-in data:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image49.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="360" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb47.png" width="657" border="0" /></a> </p>
<p>Now that the form UI is set up, we can start adding the rules and code to make it behave like a wizard.&#160; Since I like my code nice and pretty, I renamed all of my buttons to btnCancel1, btnBack1, btnNext1, btnCancel2, etc.&#160; For each cancel button, I added a rule to just close the form.</p>
<p>For the back button, we don’t need to validate the fields, so the code required to jump back to the previous page is straightforward.&#160; To switch views I used the <a href="http://msdn.microsoft.com/en-us/library/aa943181.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank">SwitchView()</a> method of the form’s <a href="http://msdn.microsoft.com/en-us/library/aa943181.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');" target="_blank">ViewInfoCollection</a>:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">public void </span>btnBack2_Clicked(<span style="color: blue">object </span>sender, <span style="color: teal">ClickedEventArgs </span>e)
{
    <span style="color: blue">this</span>.ViewInfos.SwitchView(<span style="color: maroon">&quot;page1&quot;</span>);
}

<span style="color: blue">public void </span>btnBack3_Clicked(<span style="color: blue">object </span>sender, <span style="color: teal">ClickedEventArgs </span>e)
{
    <span style="color: blue">this</span>.ViewInfos.SwitchView(<span style="color: maroon">&quot;page2&quot;</span>);
}</pre>
</div>
</p>
</p>
</p>
<p>&#160;</p>
<p>Next I needed to implement the “Next” functionality, but before we switch the view to the next page, the fields on the current page need to be validated.&#160; For this, I added the errorMessage field to each of the pages, and if the validation fails, I set the value of that field to the error message.&#160; To do the validation and to set the field, I created two wrapper methods: GetFieldValue and SetFieldValue:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">private string </span>GetFieldValue(<span style="color: blue">string </span>fieldName)
{
    <span style="color: blue">string </span>xpath = <span style="color: blue">string</span>.Format(<span style="color: maroon">&quot;/my:myFields/my:{0}&quot;</span>, fieldName);
    <span style="color: blue">return </span>MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager).Value;
}

<span style="color: blue">private void </span>SetFieldValue(<span style="color: blue">string </span>fieldName, <span style="color: blue">string </span>value)
{
    <span style="color: blue">string </span>xpath = <span style="color: blue">string</span>.Format(<span style="color: maroon">&quot;/my:myFields/my:{0}&quot;</span>, fieldName);
    MainDataSource.CreateNavigator().SelectSingleNode(xpath, NamespaceManager).SetValue(value);
}</pre>
</div>
<p>
  <br />Now for the Next buttons, I can verify data has been entered and if not, set the errorMessage field value:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 2200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: blue">public void </span>btnNext1_Clicked(<span style="color: blue">object </span>sender, <span style="color: teal">ClickedEventArgs </span>e)
{
    <span style="color: blue">if </span>(!<span style="color: blue">string</span>.IsNullOrEmpty(GetFieldValue(<span style="color: maroon">&quot;firstName&quot;</span>)) &amp;&amp;
        !<span style="color: blue">string</span>.IsNullOrEmpty(GetFieldValue(<span style="color: maroon">&quot;lastName&quot;</span>)) &amp;&amp;
        !<span style="color: blue">string</span>.IsNullOrEmpty(GetFieldValue(<span style="color: maroon">&quot;emailAddress&quot;</span>)))
    {

        SetFieldValue(<span style="color: maroon">&quot;errorMessage&quot;</span>, <span style="color: blue">string</span>.Empty);
        <span style="color: blue">this</span>.ViewInfos.SwitchView(<span style="color: maroon">&quot;page2&quot;</span>);
    }
    <span style="color: blue">else
    </span>{
        SetFieldValue(<span style="color: maroon">&quot;errorMessage&quot;</span>, <span style="color: maroon">&quot;Please fill out all required information&quot;</span>);
    }
}

<span style="color: blue">public void </span>btnNext2_Clicked(<span style="color: blue">object </span>sender, <span style="color: teal">ClickedEventArgs </span>e)
{
    <span style="color: blue">if </span>(!<span style="color: blue">string</span>.IsNullOrEmpty(GetFieldValue(<span style="color: maroon">&quot;workPhone&quot;</span>)) &amp;&amp;
        !<span style="color: blue">string</span>.IsNullOrEmpty(GetFieldValue(<span style="color: maroon">&quot;cellPhone&quot;</span>)) &amp;&amp;
        !<span style="color: blue">string</span>.IsNullOrEmpty(GetFieldValue(<span style="color: maroon">&quot;address&quot;</span>)))
    {

        SetFieldValue(<span style="color: maroon">&quot;errorMessage&quot;</span>, <span style="color: blue">string</span>.Empty);
        <span style="color: blue">this</span>.ViewInfos.SwitchView(<span style="color: maroon">&quot;page3&quot;</span>);
    }
    <span style="color: blue">else
    </span>{
        SetFieldValue(<span style="color: maroon">&quot;errorMessage&quot;</span>, <span style="color: maroon">&quot;Please fill out all required information&quot;</span>);
    }
}</pre>
</div>
<p>
  <br />The end result is something like this when an error occurs:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image50.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="497" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb48.png" width="741" border="0" /></a> </p>
<p>
  <br />If all the data has been entered successfully, the last page is eventually visible:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image51.png" ><img title="image" style="border-top-width: 0px; display: inline; border-left-width: 0px; border-bottom-width: 0px; border-right-width: 0px" height="497" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb49.png" width="741" border="0" /></a> </p>
<p>&#160;</p>
<p>Pretty slick, huh?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/02/16/creating-a-wizard-style-browser-enabled-infopath-form/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>Getting the Default SharePoint Installation Path</title>
		<link>http://www.devexpertise.com/2009/02/13/getting-the-default-sharepoint-installation-path/</link>
		<comments>http://www.devexpertise.com/2009/02/13/getting-the-default-sharepoint-installation-path/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 14:27:37 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Object Model]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/02/13/getting-the-default-sharepoint-installation-path/</guid>
		<description><![CDATA[If you ever worked with the SharePoint Object Model and have hard-coded the path to the root files (aka “12 Hive”) directory – there’s a better way.&#160; Most of the time, the root files directory is located in the following folder: C:\Program Files\Common Files\Microsoft Shared\web server extensions\12 But what if it’s not and your code [...]]]></description>
			<content:encoded><![CDATA[<p>If you ever worked with the SharePoint Object Model and have hard-coded the path to the root files (aka “12 Hive”) directory – there’s a better way.&#160; Most of the time, the root files directory is located in the following folder:</p>
<blockquote><p>C:\Program Files\Common Files\Microsoft Shared\web server extensions\12</p>
</blockquote>
<p>But what if it’s not and your code may be used on multiple systems?&#160; It doesn’t make sense to include it in a config file, and it definitely doesn’t make sense to hard code it.&#160; Luckily the OM ships with a handy little method: SPUtility.GetGenericSetupPath().&#160; Let’s take a look…</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: #2b91af">SPUtility</span>.GetGenericSetupPath(<span style="color: blue">string</span>.Empty)</pre>
</div>
<p>Returns:</p>
<p>C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\</p>
<p>&#160;</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: #2b91af">SPUtility</span>.GetGenericSetupPath(<span style="color: #a31515">&quot;TEMPLATE&quot;</span>)</pre>
</div>
<p>Returns:</p>
<blockquote>
<p>C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\</p>
</blockquote>
<p>&#160;</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: #2b91af">SPUtility</span>.GetGenericSetupPath(<span style="color: #a31515">@&quot;TEMPLATE\1033\STS\DOCTEMP\SMARTPGS&quot;</span>)</pre>
</div>
<p>Returns:</p>
<blockquote>
<p>C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\TEMPLATE\1033\STS\DOCTEMP\SMARTPGS\</p>
</blockquote>
<p>&#160;</p>
<p>If you haven’t realized it by now, all this method does is append the parameter to the root files path, meaning you <em>could</em> pass it some nonsense path and it wouldn’t care:</p>
<div style="border-right: gray 1px solid; padding-right: 4px; border-top: gray 1px solid; padding-left: 4px; font-size: 8pt; padding-bottom: 4px; margin: 20px 0px 10px; overflow: auto; border-left: gray 1px solid; width: 97.5%; cursor: text; max-height: 200px; line-height: 12pt; padding-top: 4px; border-bottom: gray 1px solid; font-family: consolas, &#39;Courier New&#39;, courier, monospace; background-color: #f4f4f4">
<pre class="code"><span style="color: #2b91af">SPUtility</span>.GetGenericSetupPath(<span style="color: #a31515">&quot;FAKEDIRECTORY&quot;</span>)</pre>
</div>
<p>Returns:</p>
<blockquote>
<p>C:\Program Files\Common Files\Microsoft Shared\web server extensions\12\FAKEDIRECTORY\</p>
</blockquote>
<p>&#160;</p>
<p>SPUtility is a hidden gem, and contains a ton of helpful methods…take a look!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/02/13/getting-the-default-sharepoint-installation-path/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Installing a Theme as a SharePoint Feature</title>
		<link>http://www.devexpertise.com/2009/02/11/installing-a-theme-as-a-sharepoint-feature/</link>
		<comments>http://www.devexpertise.com/2009/02/11/installing-a-theme-as-a-sharepoint-feature/#comments</comments>
		<pubDate>Wed, 11 Feb 2009 13:48:53 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint UI]]></category>
		<category><![CDATA[XML]]></category>
		<category><![CDATA[Themes]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/02/11/installing-a-theme-as-a-sharepoint-feature/</guid>
		<description><![CDATA[I briefly went over my approach to creating a custom SharePoint theme in my previous post, and I even included a downloadable solution package that you can install on your farm (provided you have the .NET 3.5 Framework installed).&#160; How did I accomplish this?&#160; Pretty easily actually.&#160; Unfortunately there isn’t much documentation or examples of [...]]]></description>
			<content:encoded><![CDATA[<p>I briefly went over my approach to creating a custom SharePoint theme in my <a href="http://www.devexpertise.com/2009/02/09/creating-a-custom-vista-theme-for-sharepoint/"  target="_blank">previous post</a>, and I even included a downloadable solution package that you can install on your farm (provided you have the .NET 3.5 Framework installed).&#160; How did I accomplish this?&#160; Pretty easily actually.&#160; Unfortunately there isn’t much documentation or examples of this out there, so allow me to put an end to that!</p>
<p>SharePoint features and solutions are absolutely essential if you want to provide an easy and maintainable method of deploying custom artifacts to your SharePoint servers.&#160; A theme is a perfect candidate for this, as everything is file-system based and located with the 12 directory.&#160; The only odd thing that throws a monkey wrench in this seemingly simple process is the SPTHEMES.XML file, which must be updated to include an entry for your custom theme.&#160; Here’s a portion of that file, with the custom theme I developed in my previous post highlighted:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/02/image43.png" ><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://www.devexpertise.com/wp-content/uploads/2009/02/image-thumb41.png" width="653" height="357" /></a></p>
<p>Now, you could by all means include the SPTHEMES.XML file in your solution and have it overwrite the existing file, but what if you have other themes defined in your file?&#160; That approach will overwrite it, and you’ll have to reenter everything.&#160; The recommended approach to this is to create a feature receiver that fires when the feature is installed and modifies the SPTHEMES.XML.&#160; When the feature is installed, a custom &lt;Templates&gt; section is added for the custom theme, and when it’s uninstalled it’s removed.</p>
<blockquote><p>NOTE: A feature is “installed” when you run the <strong>STSADM –o installfeature</strong> command, or when a feature is contained in a solution package and that solution package is <em>deployed</em>.</p>
</blockquote>
<p>One important thing to mention is that this feature is scoped for the farm, not an individual site-collection or site, as the files deployed to the file system are used by the entire farm.&#160; Let’s first take a look at the feature.xml file:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 1200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">&lt;?</span><span style="color: #a31515">xml </span><span style="color: red">version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0</span>&quot; <span style="color: red">encoding</span><span style="color: blue">=</span>&quot;<span style="color: blue">utf-8</span>&quot; <span style="color: blue">?&gt;
&lt;</span><span style="color: #a31515">Feature </span><span style="color: red">xmlns</span><span style="color: blue">=</span>&quot;<span style="color: blue">http://schemas.microsoft.com/sharepoint/</span>&quot;
         <span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">2D965A22-73A9-4e00-A530-06F2AF6EC89F</span>&quot;
         <span style="color: red">Title</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise Vista Theme</span>&quot;
         <span style="color: red">Description</span><span style="color: blue">=</span>&quot;<span style="color: blue">Adds the DevExpertise Vista Theme</span>&quot;
         <span style="color: red">Scope</span><span style="color: blue">=</span>&quot;<span style="color: blue">Farm</span>&quot;
         <span style="color: red">Version</span><span style="color: blue">=</span>&quot;<span style="color: blue">1.0.0.0</span>&quot;
         <span style="color: red">ImageUrl</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise\devexpertiseLogo.png</span>&quot;
         <span style="color: red">ReceiverAssembly</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise.SharePoint.Themes, Version=1.0.0.0,
                           Culture=neutral, PublicKeyToken=d39eedb6cff9b1c8</span>&quot;
         <span style="color: red">ReceiverClass </span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise.SharePoint.Themes.FeatureReceiver</span>&quot;<span style="color: blue">&gt;
&lt;/</span><span style="color: #a31515">Feature</span><span style="color: blue">&gt;</span></pre>
</div>
<p>As you can see, it is executing a custom FeatureReceiver class.&#160; At a high-level, the receiver looks like this:</p>
<p><strong><font color="#ff0000">[UPDATED 5/27/2009]<br />
      <br />I received a couple comments that let me know that if this feature is activated on a farm with multiple front-ends, then the <em>FeatureActivated</em> event only gets fired on a single web front-end.&#160; This is absolutely TRUE, and an oversight on my part (thanks guys!).&#160; The solution is extremely simple – put your code in the <em>FeatureInstalled</em> and <em>FeatureUninstalling</em> events instead, as these get fired on EVERY web front-end in your farm!!&#160; I’ve modified the code to reflect this:</font></strong></p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 1200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">public class </span><span style="color: #2b91af">FeatureReceiver</span>: <span style="color: #2b91af">SPFeatureReceiver </span>{

    <span style="color: blue">private enum </span><span style="color: #2b91af">ModificationType </span>{ Add, Remove }

    <span style="color: blue">public override void </span>FeatureInstalled(<span style="color: #2b91af">SPFeatureReceiverProperties </span>properties) {
        ModifySPTheme(<span style="color: #2b91af">ModificationType</span>.Add);

        <span style="color: green">// if necessary, loop through all sites and set theme
    </span>}

    <span style="color: blue">public override void </span>FeatureUninstalling(<span style="color: #2b91af">SPFeatureReceiverProperties </span>properties) {
        ModifySPTheme(<span style="color: #2b91af">ModificationType</span>.Remove);

        <span style="color: green">// if necessary, loop through all sites and reset theme
    </span>}

    <span style="color: blue">public override void </span>FeatureActivated(<span style="color: #2b91af">SPFeatureReceiverProperties </span>properties) {
        <span style="color: green">// do nothing
    </span>}

    <span style="color: blue">public override void </span>FeatureDeactivating(<span style="color: #2b91af">SPFeatureReceiverProperties </span>properties) {
        <span style="color: green">// do nothing
    </span>}
}</pre>
</div>
<p>For the sake of simplicity, I’m not including code to set the theme on any sites.&#160; Since this is a farm feature, it doesn’t make sense to set the theme for a particular site here, but by all means if you wanted to you could.&#160; Basically this feature receiver is only for modifying the SPTHEMES.XML file.</p>
<p>Let’s take a look at the ModifySPTheme() method.&#160; It uses LINQ to XML to open and parse the file, add the necessary elements when the feature is installed, and remove it when the feature is uninstalling:</p>
<div style="border-bottom: gray 1px solid; border-left: gray 1px solid; padding-bottom: 4px; line-height: 12pt; background-color: #f4f4f4; margin: 20px 0px 10px; padding-left: 4px; width: 97.5%; padding-right: 4px; font-family: consolas, &#39;Courier New&#39;, courier, monospace; max-height: 2200px; font-size: 8pt; overflow: auto; border-top: gray 1px solid; cursor: text; border-right: gray 1px solid; padding-top: 4px">
<pre class="code"><span style="color: blue">private void </span>ModifySPTheme(<span style="color: #2b91af">ModificationType </span>type) {
    <span style="color: #2b91af">XDocument </span>doc = <span style="color: blue">null</span>;
    <span style="color: #2b91af">XNamespace </span>ns = <span style="color: #a31515">&quot;http://tempuri.org/SPThemes.xsd&quot;</span>;

    <span style="color: green">// path to the SPTHEMES.XML file
    </span><span style="color: blue">string </span>spthemePath = <span style="color: #2b91af">Path</span>.Combine(<span style="color: #2b91af">SPUtility</span>.GetGenericSetupPath(<span style="color: #a31515">@&quot;TEMPLATE\LAYOUTS\1033&quot;</span>), <span style="color: #a31515">&quot;SPTHEMES.XML&quot;</span>);
    <span style="color: blue">string </span>contents = <span style="color: blue">string</span>.Empty;

    <span style="color: green">// read the contents of the SPTHEMES.XML file
    </span><span style="color: blue">using </span>(<span style="color: #2b91af">StreamReader </span>streamReader = <span style="color: blue">new </span><span style="color: #2b91af">StreamReader</span>(spthemePath)) {
        contents = streamReader.ReadToEnd();
        streamReader.Close();
    }

    <span style="color: blue">using </span>(<span style="color: #2b91af">StringReader </span>stringReader = <span style="color: blue">new </span><span style="color: #2b91af">StringReader</span>(contents.Trim())) {
        <span style="color: green">// create a new XDocument from the contents of the file
        </span>doc = <span style="color: #2b91af">XDocument</span>.Load(stringReader);

        <span style="color: green">// retrieve all elements with a TemplateID of 'VISTA'.  At most, there should only be one
        </span><span style="color: blue">var </span>element = <span style="color: blue">from </span>b <span style="color: blue">in </span>doc.Element(ns + <span style="color: #a31515">&quot;SPThemes&quot;</span>).Elements(ns + <span style="color: #a31515">&quot;Templates&quot;</span>)
                      <span style="color: blue">where </span>b.Element(ns + <span style="color: #a31515">&quot;TemplateID&quot;</span>).Value == <span style="color: #a31515">&quot;VISTA&quot;
                      </span><span style="color: blue">select </span>b;

        <span style="color: green">// determine if the VISTA theme element already exists
        </span><span style="color: blue">bool </span>exists = (element != <span style="color: blue">null </span>&amp;&amp; element.Count() &gt; 0);

        <span style="color: blue">if </span>(type == <span style="color: #2b91af">ModificationType</span>.Add) {
            <span style="color: blue">if </span>(!exists) {
                <span style="color: green">// create an XElement that defines our custom VISTA theme
                </span><span style="color: #2b91af">XElement </span>xml =
                    <span style="color: blue">new </span><span style="color: #2b91af">XElement</span>(ns + <span style="color: #a31515">&quot;Templates&quot;</span>,
                        <span style="color: blue">new </span><span style="color: #2b91af">XElement</span>(ns + <span style="color: #a31515">&quot;TemplateID&quot;</span>, <span style="color: #a31515">&quot;VISTA&quot;</span>),
                        <span style="color: blue">new </span><span style="color: #2b91af">XElement</span>(ns + <span style="color: #a31515">&quot;DisplayName&quot;</span>, <span style="color: #a31515">&quot;DevExpertise Vista Theme&quot;</span>),
                        <span style="color: blue">new </span><span style="color: #2b91af">XElement</span>(ns + <span style="color: #a31515">&quot;Description&quot;</span>, <span style="color: #a31515">&quot;A Vista-like Theme&quot;</span>),
                        <span style="color: blue">new </span><span style="color: #2b91af">XElement</span>(ns + <span style="color: #a31515">&quot;Thumbnail&quot;</span>, <span style="color: #a31515">&quot;images/DevExpertise.SharePoint.Themes/VISTA/thVISTA.gif&quot;</span>),
                        <span style="color: blue">new </span><span style="color: #2b91af">XElement</span>(ns + <span style="color: #a31515">&quot;Preview&quot;</span>, <span style="color: #a31515">&quot;images/DevExpertise.SharePoint.Themes/VISTA/thVISTA.gif&quot;</span>));

                <span style="color: green">// add the element to the file and save
                </span>doc.Element(ns + <span style="color: #a31515">&quot;SPThemes&quot;</span>).Add(xml);
                doc.Save(spthemePath);
            }
        }
        <span style="color: blue">else </span>{
            <span style="color: blue">if </span>(exists) {
                <span style="color: green">// if the element exists, remove it and save
                </span>element.Remove();
                doc.Save(spthemePath);
            }
        }

        stringReader.Close();
    }
}</pre>
</div>
<p>Pretty slick, huh? Now, keep in mind that this only modifies the SPTHEMES.XML file – it does NOT set the theme for any site.&#160; It will still be up to the user or site admins to set the theme for a given site.&#160; Also, if this theme is already applied to a site and the feature is deactivated, it won’t reset the theme – it will only remove the entry from the theme settings page in Site Settings.&#160; Finally, if a site has this theme installed and the solution package is uninstalled and/or removed, your site’s theme will be messed up because the source files are gone.&#160; It is probably beneficial to at least loop through all the sites and reset the theme to something else if and when the feature is deactivated, but I’ll leave that to you. Enjoy!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/02/11/installing-a-theme-as-a-sharepoint-feature/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
	</channel>
</rss>

