<?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</title>
	<atom:link href="http://www.devexpertise.com/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>SharePoint 2010 Wallpapers</title>
		<link>http://www.devexpertise.com/2010/05/12/sharepoint-2010-wallpapers/</link>
		<comments>http://www.devexpertise.com/2010/05/12/sharepoint-2010-wallpapers/#comments</comments>
		<pubDate>Wed, 12 May 2010 14:32:09 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2010/05/12/sharepoint-2010-wallpapers/</guid>
		<description><![CDATA[Not sure why, but any time I build a virtual machine I like to set its wallpaper to something that looks good, yet also identifies what the purpose of the virtual machine is.&#160; I recently just built a SharePoint Server 2010 virtual machine, and I wanted a good-looking SharePoint 2010 wallpaper for it, but couldn’t [...]]]></description>
			<content:encoded><![CDATA[<p>Not sure why, but any time I build a virtual machine I like to set its wallpaper to something that looks good, yet also identifies what the purpose of the virtual machine is.&#160; I recently just built a SharePoint Server 2010 virtual machine, and I wanted a good-looking SharePoint 2010 wallpaper for it, but couldn’t find a thing online.&#160; Since I’m no stranger to Photoshop, I decided to just make my own.&#160; Here’s what I came up with:</p>
<p><strong>SharePoint Server 2010</strong></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePoint2010Wallpaper1.jpg"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SharePoint 2010 Wallpaper 1" border="0" alt="SharePoint 2010 Wallpaper 1" src="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePoint2010Wallpaper1_thumb.jpg" width="820" height="520" /></a></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePoint2010Wallpaper2.jpg"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SharePoint 2010 Wallpaper 2" border="0" alt="SharePoint 2010 Wallpaper 2" src="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePoint2010Wallpaper2_thumb.jpg" width="820" height="520" /></a></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePoint2010Wallpaper3.jpg"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SharePoint 2010 Wallpaper 3" border="0" alt="SharePoint 2010 Wallpaper 3" src="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePoint2010Wallpaper3_thumb.jpg" width="820" height="520" /></a></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePoint2010Wallpaper4.jpg"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SharePoint 2010 Wallpaper 4" border="0" alt="SharePoint 2010 Wallpaper 4" src="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePoint2010Wallpaper4_thumb.jpg" width="820" height="520" /></a> </p>
<p><strong>     <br />SharePoint Foundation 2010</strong></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePointFoundation2010Wallpaper1.jpg"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SharePoint Foundation 2010 Wallpaper 1" border="0" alt="SharePoint Foundation 2010 Wallpaper 1" src="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePointFoundation2010Wallpaper1_thumb.jpg" width="820" height="520" /></a></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePointFoundation2010Wallpaper2.jpg"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SharePoint Foundation 2010 Wallpaper 2" border="0" alt="SharePoint Foundation 2010 Wallpaper 2" src="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePointFoundation2010Wallpaper2_thumb.jpg" width="820" height="520" /></a>&#160; </p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePointFoundation2010Wallpaper3.jpg"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SharePoint Foundation 2010 Wallpaper 3" border="0" alt="SharePoint Foundation 2010 Wallpaper 3" src="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePointFoundation2010Wallpaper3_thumb.jpg" width="820" height="520" /></a></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePointFoundation2010Wallpaper4.jpg"  rel="lightbox"><img style="border-bottom: 0px; border-left: 0px; display: inline; border-top: 0px; border-right: 0px" title="SharePoint Foundation 2010 Wallpaper 4" border="0" alt="SharePoint Foundation 2010 Wallpaper 4" src="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePointFoundation2010Wallpaper4_thumb.jpg" width="820" height="520" /></a> </p>
<p>&#160;</p>
<p>If you’re interested, you can download them from the following location.&#160; Enjoy!</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:d4d922f1-ca04-4386-aedc-15d12f31d1f4" class="wlWriterEditableSmartContent">
<p> <a href="http://www.devexpertise.com/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePoint2010Wallpapers.zip" onclick="javascript:pageTracker._trackPageview('/downloads/wp-content/uploads/Images%20for%20Posts/SharePoint2010Wallpapers_8428/SharePoint2010Wallpapers.zip');" target="_blank">SharePoint 2010 Wallpapers</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2010/05/12/sharepoint-2010-wallpapers/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<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>Fixing the &quot;Selected file was not found&#8221; Error When Adding an Attachment to an InfoPath Workflow Task Form</title>
		<link>http://www.devexpertise.com/2009/07/01/fixing-the-selected-file-was-not-found-error-when-adding-an-attachment-to-an-infopath-workflow-task-form/</link>
		<comments>http://www.devexpertise.com/2009/07/01/fixing-the-selected-file-was-not-found-error-when-adding-an-attachment-to-an-infopath-workflow-task-form/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 21:07:24 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[InfoPath]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[Workflow]]></category>
		<category><![CDATA[Features]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/07/01/fixing-the-selected-file-was-not-found-error-when-adding-an-attachment-to-an-infopath-workflow-task-form/</guid>
		<description><![CDATA[If you’re at all familiar with creating Visual Studio-authored workflows for SharePoint, you’re probably aware that you can also create custom task forms for tasks that have been assigned in that workflow.&#160; The task forms can either be implemented as ASP.NET forms or InfoPath forms. My personal preference is InfoPath, provided the functionality that is [...]]]></description>
			<content:encoded><![CDATA[<p>If you’re at all familiar with creating Visual Studio-authored workflows for SharePoint, you’re probably aware that you can also create custom task forms for tasks that have been assigned in that workflow.&#160; The task forms can either be implemented as ASP.NET forms or InfoPath forms. My personal preference is InfoPath, provided the functionality that is needed can be accomplished using InfoPath.&#160; By choosing InfoPath, much of the overhead required to allow SharePoint to use it as a task form is already done, whereas with ASP.NET it’s up to the developer to implement. </p>
<p>On a recent project, I had a need to create a workflow that at a certain step, prompted the user to upload a file attachment.&#160; InfoPath was the obvious choice because they’re simple to create, simple to deploy, and they even support attachments.&#160; After creating the form and the workflow I tried attaching a file to the InfoPath task form, and received the following error message:</p>
<p>&#160;<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/FixingtheSelectedfilewasnotfoundErrorWhe_B431/image_thumb.png" width="540" height="334" /></p>
<p>I searched around a little and found that this is a known issue, and there are a few ways to fix it.&#160; <a href="http://stackoverflow.com/questions/189184/the-selected-files-was-not-found-on-an-infopath-form-in-sharepoint" onclick="javascript:pageTracker._trackPageview('/outbound/article/stackoverflow.com');">This post suggests</a> adding the following bit of JavaScript to the WrkTaskIP.aspx page, which is responsible for hosting the InfoPath task form:</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">script </span><span style="color: red">type</span><span style="color: blue">=&quot;text/javascript&quot;&gt;
    </span>aspnetForm.encoding = <span style="color: #a31515">&quot;multipart/form-data&quot;</span>;
<span style="color: blue">&lt;/</span><span style="color: #a31515">script</span><span style="color: blue">&gt;</span></pre>
</div>
<p>Another approach documented here suggests modifying the application.master master page file to add the necessary enctype form tag:</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">form </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">onsubmit</span><span style="color: blue">=&quot;return _spFormOnSubmitWrapper();&quot; </span><span style="color: red">enctype</span><span style="color: blue">=&quot;multipart/form-data&quot;&gt;
  </span>...
<span style="color: blue">&lt;/</span><span style="color: #a31515">form</span></pre>
</div>
<p>While both of these approaches work, I wasn’t completely happy with modifying out-of-the-box SharePoint files, which isn’t recommended anyways.&#160; I took a slightly more involved, but much more reusable approach. Any customization you make to SharePoint really should be implemented as a Feature.&#160; I’m not going to go into the nuts and bolts of what features are, but you can learn a little more about them from this <a href="http://www.devexpertise.com/2009/04/01/integrating-a-custom-aspnet-application-into-sharepoint-part-4/" >previous post</a>.&#160; Before I explain my approach, here are your options for accomplishing this:</p>
<ol>
<li>Modify the out-of-the-box application.master master page file on the file system.&#160; Not recommended. </li>
<li>Modify the out-of-the-box WrkTaskIP.aspx page on the file system.&#160; Not recommended. </li>
<li>Create a new task content type, create a copy of WrkTaskIP.aspx and rename it, add the JavaScript to that page, associate the new ASPX page to your new content type, then point your workflow task forms to that new content type.&#160; Not impossible, better than the above approaches, but still a lot of unnecessary work. </li>
<li>Create a user control with the necessary script and deploy it as a delegate control feature.&#160; Recommend, and the approach I describe in this post. </li>
</ol>
<p>I decided to go with JavaScript, because I knew I could insert that into a page a lot easier than I could insert a form tag attribute.&#160; Using an approach I’ve used before on previous projects, I decided to implement this using the delegate control pattern.&#160; Take a look <a href="http://www.sharepointnutsandbolts.com/2007/06/using-delegate-control.html" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.sharepointnutsandbolts.com');">here</a> and <a href="http://msdn.microsoft.com/en-us/library/ms463169.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">here</a> first for a primer on delegate controls, but basically what they allow you to do is insert custom user or server controls into a place holder in the master page using a feature.&#160; This is perfect, because you can add functionality to all site pages immediately without actually modifying a single page.</p>
<p>The first step is creating the user control that will be responsible for adding the encoding to the form.&#160; I took a little different approach here too, and used jQuery to attach the encoding element to the forms. Obviously this implies that the jQuery library is being referenced already.&#160; There are other solutions that make this a cinch to accomplish, <a href="http://www.codeplex.com/smarttools/Wiki/View.aspx?title=jQuery" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.codeplex.com');">such as this one</a> by the great Jan Tielens.&#160; In fact, this solution uses the exact same approach that I’m blogging about here.&#160; My DevExpertise.TaskFormEncoding.ascx user control looks 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="background: #ffee62">&lt;%</span><span style="color: blue">@ </span><span style="color: #a31515">Control </span><span style="color: red">Language</span><span style="color: blue">=&quot;C#&quot; </span><span style="color: red">ClassName</span><span style="color: blue">=&quot;DevExpertiseTaskFormEncoding&quot; </span><span style="background: #ffee62">%&gt;
</span><span style="color: blue">&lt;</span><span style="color: #a31515">script </span><span style="color: red">type</span><span style="color: blue">=&quot;text/javascript&quot; &gt;
    </span>$(document).ready(<span style="color: blue">function</span>() {
        $(<span style="color: #a31515">&quot;form&quot;</span>).each(<span style="color: blue">function</span>(i) {
            <span style="color: blue">this</span>.encoding = <span style="color: #a31515">&quot;multipart/form-data&quot;</span>;
        });
    });
<span style="color: blue">&lt;/</span><span style="color: #a31515">script</span><span style="color: blue">&gt;</span></pre>
</div>
<p>Now that I have the user control created, I need to create a SharePoint feature to insert this into a delegate control placeholder.&#160; Both the default.master page and application.master pages that SharePoint use by default have a delegate control named AdditionalPageHead, which is there specifically for this purpose – to add script, CSS references, etc. to the page’s HEAD section:</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">SharePoint</span><span style="color: blue">:</span><span style="color: #a31515">DelegateControl </span><span style="color: red">runat</span><span style="color: blue">=&quot;server&quot; </span><span style="color: red">ControlId</span><span style="color: blue">=&quot;AdditionalPageHead&quot; </span><span style="color: red">AllowMultipleControls</span><span style="color: blue">=&quot;true&quot;/&gt;</span></pre>
</div>
<p>The following snippet is my feature.xml file, which defines the feature.&#160; This file is responsible for specifying the feature ID, Title, Description, etc., plus any element manifests that our feature requires:</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">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">2D597698-5FBC-482a-BA0F-2E42DEA2E8E4</span>&quot;
         <span style="color: red">Title</span><span style="color: blue">=</span>&quot;<span style="color: blue">DevExpertise InfoPath Workflow Task Form Encoding</span>&quot;
         <span style="color: red">Description</span><span style="color: blue">=</span>&quot;<span style="color: blue">Adds the necessary form encoding to allow attachments
                      to be added to InfoPath workflow task forms.</span>&quot;
         <span style="color: red">Scope</span><span style="color: blue">=</span>&quot;<span style="color: blue">Site</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: 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">elements.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>This feature is expecting an elements.xml manifest file, which is responsible for wiring up my custom user control to the AdditionalPageHead delegate control in the master 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">&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">Control
    </span><span style="color: red">Id</span><span style="color: blue">=</span>&quot;<span style="color: blue">AdditionalPageHead</span>&quot;
    <span style="color: red">ControlSrc</span><span style="color: blue">=</span>&quot;<span style="color: blue">~/_controltemplates/DevExpertise/DevExpertise.TaskFormEncoding.ascx</span>&quot;
    <span style="color: red">Sequence</span><span style="color: blue">=</span>&quot;<span style="color: blue">10</span>&quot;<span style="color: blue">/&gt;
&lt;/</span><span style="color: #a31515">Elements</span><span style="color: blue">&gt;</span></pre>
</div>
<p>The only thing left is packaging everything up and deploying it. I always package my features up into solution packages using <a href="http://www.codeplex.com/wspbuilder" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.codeplex.com');">WSPBuilder</a>, since a solution package can be used to deploy other feature-dependant files to SharePoint’s 12 folder structure. My entire solution folder structure looks like this:</p>
<p><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/FixingtheSelectedfilewasnotfoundErrorWhe_B431/image_thumb_3.png" width="365" height="278" /></p>
<p>Create the solution package, deploy it to SharePoint, and you will have a site collection feature ready for activation:</p>
<p><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/FixingtheSelectedfilewasnotfoundErrorWhe_B431/image_thumb_4.png" width="685" height="84" /></p>
<p>That’s it!&#160; Now you can successfully add attachments:</p>
<p><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/FixingtheSelectedfilewasnotfoundErrorWhe_B431/image_thumb_5.png" width="494" height="261" /></p>
<p>You may be asking yourself why I went through all that trouble just to add a couple lines of JavaScript to my pages, when I could’ve just opened application.master and thrown it in there.&#160; Well, it’s not a recommended best practice to modify system files.&#160; If an update or service pack is installed that overwrites these files, then all your modifications are gone.&#160; In addition, a change like that would have to be made to all web front-end servers in your farm.&#160; This approach is extremely reusable – I can take this solution package and activate it in any site collection in any farm and I have the necessary functionality.</p>
<p>I’m feeling generous today and decided to include the solution package for your downloading pleasure.&#160; As always, it comes 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:1f9bc649-da19-462c-af64-7be97240801b" class="wlWriterEditableSmartContent">
<p>Download: <a href="http://www.devexpertise.com/wp-content/uploads/FixingtheSelectedfilewasnotfoundErrorWhe_B431/DevExpertise.TaskFormEncoding.wsp"  target="_blank">DevExpertise.TaskFormEncoding.wsp</a></p>
</div>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/07/01/fixing-the-selected-file-was-not-found-error-when-adding-an-attachment-to-an-infopath-workflow-task-form/feed/</wfw:commentRss>
		<slash:comments>2</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>SQL Tip/Trick: Retrieving Records as a Comma-Delimited Value Using FOR XML and STUFF</title>
		<link>http://www.devexpertise.com/2009/04/14/sql-tiptrick-retrieving-records-as-a-comma-delimited-value-using-for-xml-and-stuff/</link>
		<comments>http://www.devexpertise.com/2009/04/14/sql-tiptrick-retrieving-records-as-a-comma-delimited-value-using-for-xml-and-stuff/#comments</comments>
		<pubDate>Tue, 14 Apr 2009 12:50:49 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[T-SQL]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/04/14/sql-tiptrick-retrieving-records-as-a-comma-delimited-value-using-for-xml-and-stuff/</guid>
		<description><![CDATA[Once in awhile I run across a need to create a delimited list from a set of rows in a SQL table.&#160; The old-school method is to use a cursor to iterate over these rows and build a dynamic string.&#160; As we all know, cursors are expensive and should be avoided whenever possible.&#160; I recently [...]]]></description>
			<content:encoded><![CDATA[<p>Once in awhile I run across a need to create a delimited list from a set of rows in a SQL table.&#160; The old-school method is to use a cursor to iterate over these rows and build a dynamic string.&#160; As we all know, cursors are expensive and should be avoided whenever possible.&#160; I recently found a better way to accomplish this and wanted to share it in case you’ve run into this before.</p>
<p>For this example, I’m going to be working with a simple Cities table that contains a City field and a State field.&#160; A simple SELECT statement yields the following result:</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">select </span><span style="color: gray">* </span><span style="color: blue">from </span>Cities <span style="color: blue">where State </span><span style="color: gray">= </span><span style="color: red">'New York'</span></pre>
</div>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/04/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/04/image-thumb5.png" width="186" height="139" /></a> </p>
</p>
<p>
  <br />The first step is to transform this result into a chunk of XML, and for that the <a href="http://msdn.microsoft.com/en-us/library/ms345137.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">FOR XML</a> statement is perfect.&#160; Consider the following SQL:</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">declare </span>@xml <span style="color: blue">varchar</span><span style="color: gray">(</span>1000<span style="color: gray">)
</span><span style="color: blue">set </span>@xml <span style="color: gray">= (</span><span style="color: blue">select </span>City <span style="color: blue">from </span>Cities <span style="color: blue">where State </span><span style="color: gray">= </span><span style="color: red">'New York' </span><span style="color: blue">for xml path</span><span style="color: gray">(</span><span style="color: red">''</span><span style="color: gray">))</span></pre>
</div>
<p>
  <br />This returns the following (I trimmed it down a little to fit on the page, but it does return all rows):</p>
<blockquote>
<p><strong>&lt;City&gt;New York City&lt;/City&gt;&lt;City&gt;Buffalo&lt;/City&gt;&lt;City&gt;Rochester&lt;/City&gt;</strong></p>
</blockquote>
<p>Now that we have an XML string, we can just use the built-in REPLACE functions to remove the XML nodes:</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">set </span>@xml <span style="color: gray">= </span><span style="color: magenta">replace</span><span style="color: gray">(</span>@xml<span style="color: gray">, </span><span style="color: red">'&lt;City&gt;'</span><span style="color: gray">, </span><span style="color: red">','</span><span style="color: gray">)
</span><span style="color: blue">set </span>@xml <span style="color: gray">= </span><span style="color: magenta">replace</span><span style="color: gray">(</span>@xml<span style="color: gray">, </span><span style="color: red">'&lt;/City&gt;'</span><span style="color: gray">,</span><span style="color: red">''</span><span style="color: gray">)</span></pre>
</div>
<p>
  <br />This returns the following:</p>
<blockquote>
<p><strong>,New York City,Buffalo,Rochester,Yonkers,Syracuse</strong></p>
</blockquote>
<p>Now, the only thing left is to remove the beginning space and comma from this for which the new SQL 2008 <a href="http://msdn.microsoft.com/en-us/library/ms188043.aspx" onclick="javascript:pageTracker._trackPageview('/outbound/article/msdn.microsoft.com');">STUFF</a> function is perfect:</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">select </span><span style="color: magenta">stuff</span><span style="color: gray">(</span>@xml<span style="color: gray">,</span>1<span style="color: gray">,</span>1<span style="color: gray">,</span><span style="color: red">''</span><span style="color: gray">)</span></pre>
</div>
<p>
  <br />This returns the following, which is exactly what we need:</p>
<blockquote>
<p><strong>New York City,Buffalo,Rochester,Yonkers,Syracuse</strong></p>
</blockquote>
<p>Now, chances are you don’t want to have to declare variables and do all this in multiple operations.&#160; This can all be wrapped into a single select statement, which makes it easy to implement:</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">select </span><span style="color: magenta">stuff</span><span style="color: gray">((</span><span style="color: magenta">replace</span><span style="color: gray">(</span><span style="color: magenta">replace</span><span style="color: gray">(
       (</span><span style="color: blue">select </span>City <span style="color: blue">from </span>Cities <span style="color: blue">where State </span><span style="color: gray">= </span><span style="color: red">'New York' </span><span style="color: blue">for xml path</span><span style="color: gray">(</span><span style="color: red">''</span><span style="color: gray">)), </span><span style="color: red">'&lt;City&gt;'</span><span style="color: gray">, </span><span style="color: red">','
       </span><span style="color: gray">), </span><span style="color: red">'&lt;/City&gt;'</span><span style="color: gray">,</span><span style="color: red">''</span><span style="color: gray">)),</span>1<span style="color: gray">,</span>1<span style="color: gray">,</span><span style="color: red">''</span><span style="color: gray">)</span></pre>
</div>
<p>&#160;</p>
<p>That’s it!&#160; Pretty slick, huh?</p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/04/14/sql-tiptrick-retrieving-records-as-a-comma-delimited-value-using-for-xml-and-stuff/feed/</wfw:commentRss>
		<slash:comments>2</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>Ten Free SharePoint Themes</title>
		<link>http://www.devexpertise.com/2009/03/20/ten-free-sharepoint-themes/</link>
		<comments>http://www.devexpertise.com/2009/03/20/ten-free-sharepoint-themes/#comments</comments>
		<pubDate>Fri, 20 Mar 2009 12:59:11 +0000</pubDate>
		<dc:creator>DevExpert</dc:creator>
				<category><![CDATA[SharePoint]]></category>
		<category><![CDATA[SharePoint UI]]></category>
		<category><![CDATA[Themes]]></category>

		<guid isPermaLink="false">http://www.devexpertise.com/2009/03/20/ten-free-sharepoint-themes/</guid>
		<description><![CDATA[The Ten Themes for SharePoint in VSeWSS was just released and contains 10 very cool themes, absolutely free and full of glitzy eye candy.&#160; I personally don’t use VSeWSS, but you can just extract the contents of the MSI file and pull out the THEMES and LAYOUTS folders within the Visual Studio solutions, and use [...]]]></description>
			<content:encoded><![CDATA[<p>The <a href="http://www.microsoft.com/downloads/details.aspx?displaylang=en&amp;FamilyID=0a87658f-20b8-4dcc-ad7a-09ad22641f3a" onclick="javascript:pageTracker._trackPageview('/outbound/article/www.microsoft.com');">Ten Themes for SharePoint in VSeWSS</a> was just released and contains 10 very cool themes, absolutely free and full of glitzy eye candy.&#160; I personally don’t use VSeWSS, but you can just extract the contents of the MSI file and pull out the THEMES and LAYOUTS folders within the Visual Studio solutions, and use that for a custom theme.&#160; </p>
<p>For tips and tricks on how to properly deploy themes to your SharePoint environment, take a look at my previous post <a href="http://www.devexpertise.com/2009/02/11/installing-a-theme-as-a-sharepoint-feature/" >here</a>, and you may also be interested in the Vista theme I put together that I describe <a href="http://www.devexpertise.com/2009/02/09/creating-a-custom-vista-theme-for-sharepoint/" >here</a>.</p>
<p>Here are screenshots of the ten free themes:</p>
<p><strong><em>Construction:</em></strong></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/construction-preview.jpg"  rel="lightbox"><img title="Construction_Preview" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="628" alt="Construction_Preview" src="http://www.devexpertise.com/wp-content/uploads/2009/03/construction-preview-thumb.jpg" width="720" border="0" /></a><strong><em>        <br /></em></strong></p>
<p><strong><em>Contoso</em>:</strong></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/contoso-preview.jpg"  rel="lightbox"><img title="Contoso_Preview" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="464" alt="Contoso_Preview" src="http://www.devexpertise.com/wp-content/uploads/2009/03/contoso-preview-thumb.jpg" width="720" border="0" /></a></p>
<p><strong><em>Corporate</em>:</strong></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/corporate-preview.jpg"  rel="lightbox"><img title="Corporate_Preview" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="541" alt="Corporate_Preview" src="http://www.devexpertise.com/wp-content/uploads/2009/03/corporate-preview-thumb.jpg" width="720" border="0" /></a></p>
<p><strong><em>Events</em>:</strong></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/events-preview.jpg"  rel="lightbox"><img title="Events_Preview" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="613" alt="Events_Preview" src="http://www.devexpertise.com/wp-content/uploads/2009/03/events-preview-thumb.jpg" width="720" border="0" /></a></p>
<p><strong><em>OARP</em></strong>:</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/oarp-preview.jpg"  rel="lightbox"><img title="OARP_Preview" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="608" alt="OARP_Preview" src="http://www.devexpertise.com/wp-content/uploads/2009/03/oarp-preview-thumb.jpg" width="720" border="0" /></a></p>
<p><strong><em>Procurement:</em></strong></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/procurement-preview.jpg"  rel="lightbox"><img title="Procurement_Preview" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="621" alt="Procurement_Preview" src="http://www.devexpertise.com/wp-content/uploads/2009/03/procurement-preview-thumb.jpg" width="720" border="0" /></a></p>
<p><strong><em>Publishing:</em></strong>&#160;</p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/publishing-preview.jpg"  rel="lightbox"><img title="Publishing_Preview" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="608" alt="Publishing_Preview" src="http://www.devexpertise.com/wp-content/uploads/2009/03/publishing-preview-thumb.jpg" width="720" border="0" /></a></p>
<p><strong><em>Sporting:</em></strong></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/sporting-preview.jpg"  rel="lightbox"><img title="sporting_Preview" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="623" alt="sporting_Preview" src="http://www.devexpertise.com/wp-content/uploads/2009/03/sporting-preview-thumb.jpg" width="720" border="0" /></a></p>
<p><strong><em>Startup:</em></strong></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/startup-preview.jpg"  rel="lightbox"><img title="Start-Up_Preview" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="608" alt="Start-Up_Preview" src="http://www.devexpertise.com/wp-content/uploads/2009/03/startup-preview-thumb.jpg" width="720" border="0" /></a></p>
<p><strong><em>Team:</em></strong></p>
<p><a href="http://www.devexpertise.com/wp-content/uploads/2009/03/team-preview.jpg"  rel="lightbox"><img title="Team_Preview" style="border-right: 0px; border-top: 0px; display: inline; border-left: 0px; border-bottom: 0px" height="588" alt="Team_Preview" src="http://www.devexpertise.com/wp-content/uploads/2009/03/team-preview-thumb.jpg" width="720" border="0" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.devexpertise.com/2009/03/20/ten-free-sharepoint-themes/feed/</wfw:commentRss>
		<slash:comments>1</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>
	</channel>
</rss>

