<?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>TCSC Blog</title>
	<atom:link href="http://www.tcscblog.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.tcscblog.com</link>
	<description>TCSC Blog</description>
	<lastBuildDate>Mon, 13 Feb 2012 21:25:02 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Custom Error Page with Log Support Ticket Link for SharePoint 2010</title>
		<link>http://www.tcscblog.com/2012/02/10/custom-error-page-with-log-support-ticket-link-for-sharepoint-2010/</link>
		<comments>http://www.tcscblog.com/2012/02/10/custom-error-page-with-log-support-ticket-link-for-sharepoint-2010/#comments</comments>
		<pubDate>Fri, 10 Feb 2012 22:00:13 +0000</pubDate>
		<dc:creator>Adam Preston</dc:creator>
				<category><![CDATA[Configuration]]></category>
		<category><![CDATA[SharePoint 2010]]></category>

		<guid isPermaLink="false">http://www.tcscblog.com/?p=2020</guid>
		<description><![CDATA[We&#8217;ve all seen it; the SharePoint 2010 error message with its bold red X yelling at us that we have done something terribly wrong (like it&#8217;s our fault!). Every time I see it I think of the Tommy Boy line &#8230; <a href="http://www.tcscblog.com/2012/02/10/custom-error-page-with-log-support-ticket-link-for-sharepoint-2010/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>We&#8217;ve all seen it; the SharePoint 2010 error message with its bold red X yelling at us that we have done something terribly wrong (like it&#8217;s our fault!). Every time I see it I think of the Tommy Boy line &#8220;What&#8217;d you do!!?&#8221;
</p>
<p><img src="http://www.tcscblog.com/wp-content/uploads/2012/02/021012_2159_CustomError1.png" alt=""/>
	</p>
<p>Now, I like the Correlation ID and being able to track the error down. However, in real world scenarios it&#8217;s unlikely that our users will leave this screen up and copy/paste to our support group. Wouldn&#8217;t it be nice to have a warmer error message with our company logo and a link that will ask the user to send the error details? If not, then you have come to the wrong article!
</p>
<p>Error message we start with
</p>
<p><img src="http://www.tcscblog.com/wp-content/uploads/2012/02/021012_2159_CustomError2.png" alt=""/>
	</p>
<p>Error message we end with
</p>
<p><img src="http://www.tcscblog.com/wp-content/uploads/2012/02/021012_2159_CustomError3.png" alt=""/>
	</p>
<p>The user can click the &#8220;<strong>Log SharePoint Support Ticket</strong>&#8221; link and their email client will load with the prefilled body message asking them to copy and paste the Error Gibberish.
</p>
<p><img src="http://www.tcscblog.com/wp-content/uploads/2012/02/021012_2159_CustomError4.png" alt=""/>
	</p>
<p><img src="http://www.tcscblog.com/wp-content/uploads/2012/02/021012_2159_CustomError5.png" alt=""/>
	</p>
<p>Let&#8217;s see how we make the magic happen.
</p>
<p>Locate and copy the error.aspx file in Layouts folder of the 14 Hive (%PROGRAM FILES%\Common Files\Microsoft Shared\Web Server Extensions\14\TEMPLATE\LAYOUTS). <strong><em>Never never never ever</em></strong> touch the system files…make copies and use those.
</p>
<p>Create a new folder in the Layouts folder (ex. CustomError) and then paste the copied error.aspx file. Now, I&#8217;m not going to go through each line item and explain how I got the company logo or added the link. I&#8217;ve included my custom error in a zip file at the end of this blog post for you to dissect. We are going to assume that you have one edited to your liking and are ready to replace the default error message.
</p>
<p>Open up your best friend, SharePoint 2010 Management Shell, and perform the following command:
</p>
<p><span style="font-family:Lucida Console; font-size:9pt">Set-SPCustomLayoutPage -Identity Error -RelativePath &#8220;/_layouts/CustomError/error.aspx&#8221; -WebApplication &lt;webappURL&gt;<br />
</span></p>
<p><img src="http://www.tcscblog.com/wp-content/uploads/2012/02/021012_2159_CustomError6.png" alt=""/>
	</p>
<p>Then perform an <strong>IISRESET</strong>. Next, do something to break SharePoint (<em>how many time will you here that request?</em>) and test out your error message.
</p>
<p>At any point, you can set the error page back to the default by running the following command and then IISRESET:
</p>
<p><span style="font-family:Lucida Console; font-size:9pt">Set-SPCustomLayoutPage -Identity Error -WebApplication &lt;webappURL&gt; -Reset<br />
</span></p>
<p><img src="http://www.tcscblog.com/wp-content/uploads/2012/02/021012_2159_CustomError7.png" alt=""/>
	</p>
<p>Pretty cool stuff. Check out the other custom layout pages you can set like AccessDenied, Login, WebDeleted and more!
</p>
<p><a href="http://www.tcscblog.com/wp-content/uploads/2012/02/CustomErrorPage.zip">Download the Custom Error Page</a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tcscblog.com/2012/02/10/custom-error-page-with-log-support-ticket-link-for-sharepoint-2010/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Missing EXE Extension for IE Downloads</title>
		<link>http://www.tcscblog.com/2012/02/09/missing-exe-extension-for-ie-downloads/</link>
		<comments>http://www.tcscblog.com/2012/02/09/missing-exe-extension-for-ie-downloads/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 13:16:28 +0000</pubDate>
		<dc:creator>Rick Matherly</dc:creator>
				<category><![CDATA[Internet Explorer]]></category>

		<guid isPermaLink="false">http://www.tcscblog.com/?p=2008</guid>
		<description><![CDATA[I was recently working with one of our client&#8217;s websites to switch their downloads to an external Content Delivery Network (CDN). After making the transition, we started seeing a strange behavior in IE when downloading an EXE file&#8230; the extension &#8230; <a href="http://www.tcscblog.com/2012/02/09/missing-exe-extension-for-ie-downloads/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I was recently working with one of our client&#8217;s websites to switch their downloads to an external Content Delivery Network (CDN). After making the transition, we started seeing a strange behavior in IE when downloading an EXE file&#8230; the extension was missing. The odd thing was that all the other browsers we tested worked correctly.</p>
<p>After several hours of troubleshooting and research, I determined the following conditions are necessary to reproduce this behavior:</p>
<ol>
<li>The download URL contains a query string.</li>
<li>The download response does not contain a Content-Disposition header.</li>
</ol>
<p>Without the Content-Disposition header to tell IE the filename, it looks at the URL, but when there is a query string, it ignores the extension from the base URL. One common scenario where this could happen is if you have a download handler that takes an ID and looks up a file to return, probably from some type of database or secure storeage. In our case, the query string value was used as an authorization token.</p>
<p>There are 3 possible solutions to this issue:</p>
<ol>
<li>Remove the query string. This is probably not an option in most cases.</li>
<li>Add a Content-Disposition header to the response that looks something like this: Content-Disposition: attachment; filename=myfile.exe. This is the best option if you are able to make changes to the download response.</li>
<li>Add another query string value to the end of the URL such that it ends in &#8220;.exe&#8221;. For example: http://www.mysite.com/download.aspx?id=5&amp;filename=test.exe. IE will see the &#8220;.exe&#8221; at the end of the URL and set the extension correctly.</li>
</ol>
<p>See the following Microsoft KB article for more information: <a title="http://support.microsoft.com/kb/221805" href="http://support.microsoft.com/kb/221805" target="_blank">http://support.microsoft.com/kb/221805</a>. This is a very old article, but it seems to apply. The behavior is described as a bug that has been fixed, but if you read the last sentance it says that the behavior has remained unchanged for EXE and DLL files.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tcscblog.com/2012/02/09/missing-exe-extension-for-ie-downloads/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SharePoint Feature Receiver code for bin deployments</title>
		<link>http://www.tcscblog.com/2012/02/08/sharepoint-feature-receiver-code-for-bin-deployments/</link>
		<comments>http://www.tcscblog.com/2012/02/08/sharepoint-feature-receiver-code-for-bin-deployments/#comments</comments>
		<pubDate>Thu, 09 Feb 2012 01:45:27 +0000</pubDate>
		<dc:creator>Jim Brocato</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://www.tcscblog.com/2012/02/08/sharepoint-feature-receiver-code-for-bin-deployments/</guid>
		<description><![CDATA[NOTE:  If your feature receiver code needs to access the main Presentation assembly, you will receiver an error saying that the assembly UNOS.[app].Presentation cannot be loaded- this happens because the assembly is added to the bin, then the feature receiver &#8230; <a href="http://www.tcscblog.com/2012/02/08/sharepoint-feature-receiver-code-for-bin-deployments/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p style="margin-left: 117pt"><span style="color:#676767"><span style="font-family:Consolas; font-size:9pt">NOTE:  If your feature receiver code needs to access the main Presentation assembly, you will receiver an error saying that the assembly UNOS.[app].Presentation cannot be loaded- this happens because the assembly is added to the bin, then the feature receiver code runs before the app pool recycles, so the assembly is never loaded into context.  To work around this, add this line to your feature receiver code:</span><span style="font-family:Verdana; font-size:8pt"><br />
			</span></span></p>
<p style="margin-left: 117pt"><span style="color:#2b91af; font-family:Consolas"><span style="font-size:8pt">Assembly<span style="color:#676767">.LoadFrom(<span style="color:#a31515">@&#8221;C:\inetpub\wwwroot\wss\VirtualDirectories\[app]\bin\TCSC.Assembly.Name.dll&#8221;<span style="color:#676767">);</span></span></span></span><span style="font-size:9pt"><br />
			</span></span></p>
<p style="margin-left: 117pt"> <br />
 </p>
<p style="margin-left: 117pt"><span style="color:#676767; font-family:Consolas; font-size:9pt">which will use Reflection to load the assembly into context for the duraction of the feature receiver activation method.<br />
</span></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tcscblog.com/2012/02/08/sharepoint-feature-receiver-code-for-bin-deployments/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Adding to a SharePoint 2010 List with Lookups</title>
		<link>http://www.tcscblog.com/2012/01/31/adding-to-a-sharepoint-2010-list-with-lookups/</link>
		<comments>http://www.tcscblog.com/2012/01/31/adding-to-a-sharepoint-2010-list-with-lookups/#comments</comments>
		<pubDate>Tue, 31 Jan 2012 23:06:55 +0000</pubDate>
		<dc:creator>Rick Matherly</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[Linq to SharePoint]]></category>
		<category><![CDATA[SharePoint 2010]]></category>
		<category><![CDATA[LINQ]]></category>
		<category><![CDATA[SPMetal]]></category>

		<guid isPermaLink="false">http://www.tcscblog.com/?p=1996</guid>
		<description><![CDATA[I had a situation recently where I was building a form in SharePoint 2010. I used a main list for the form and several other lists as lookup values for some of the fields. I used a .NET User Control &#8230; <a href="http://www.tcscblog.com/2012/01/31/adding-to-a-sharepoint-2010-list-with-lookups/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I had a situation recently where I was building a form in SharePoint 2010. I used a main list for the form and several other lists as lookup values for some of the fields. I used a .NET User Control for the UI, and SPMetal and LINQ to interact with SharePoint. This was my first time using SPMetal, and I had trouble adding items to the main list. The error was coming from the lookup fields. I eventually figured out that you can&#8217;t assign lookup field values to an item while you are adding it. You have to create the item first without the lookup values, then go back and add them.</p>
<p>The resulting code looks something like this:</p>
<p style="color: #222; padding: 20px; background-color: #f7f7f7;">demoData = new DemoDataContext(SPContext.Current.Site.Url);<br />
var demoItem = new DemoItem();<br />
demoItem.Title = &#8220;New Demo Item&#8221;;<br />
// Set other properties here&#8230; except lookups<br />
demoData.DemoItems.InsertOnSubmit(demoItem);<br />
demoData.SubmitChanges();<br />
var demoItemID = (int)demoItem.Id;<br />
// Get a new context and load the item back up using the ID<br />
demoData = new DemoDataContext(SPContext.Current.Site.Url);<br />
demoItem = (from demoItem<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;in demoData.DemoItems<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;where demoItem.Id == demoItemID<br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select demoItem).Single();<br />
// Set the lookup properties here<br />
demoData.SubmitChanges();</p>
<p>I welcome your feedback if anyone knows a better way to do this, but this was the only way I could get it to work.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tcscblog.com/2012/01/31/adding-to-a-sharepoint-2010-list-with-lookups/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Team Foundation Server: Unshelving another user’s changes across branches</title>
		<link>http://www.tcscblog.com/2012/01/23/team-foundation-server-unshelving-another-user%e2%80%99s-changes-across-branches/</link>
		<comments>http://www.tcscblog.com/2012/01/23/team-foundation-server-unshelving-another-user%e2%80%99s-changes-across-branches/#comments</comments>
		<pubDate>Mon, 23 Jan 2012 13:14:44 +0000</pubDate>
		<dc:creator>Tom Becker</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Visual Studio]]></category>

		<guid isPermaLink="false">http://www.tcscblog.com/?p=1989</guid>
		<description><![CDATA[Unshelving code between branches can be difficult enough on its own but once you add another developer into the mix things can get a bit dicey since Visual Studio does not have a built-in wizard to do this. To unshelve &#8230; <a href="http://www.tcscblog.com/2012/01/23/team-foundation-server-unshelving-another-user%e2%80%99s-changes-across-branches/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>Unshelving code between branches can be difficult enough on its own but once you add another developer into the mix things can get a bit dicey since Visual Studio does not have a built-in wizard to do this.</p>
<p>To unshelve into a different branch you have to use the TFS PowerTools PowerShell Console.  The <a href="http://msdn.microsoft.com/en-us/library/s6bx4df3.aspx">MSDN article</a> has all of the details of the unshelve command but I’m just going to give you the command to unshelve someone else’s changes across branches since that is where it threw me.  In order to unshelve someone else’s changes you must include their username as a part of the shelf name, but you cannot forget the quotes around it or else TFS will think the shelf is yours.</p>
<p><code>PS C:\MyTargetRoot\&gt; tfpt unshelve “ShelfSetName;UserName” /migrate /source:”$/source branch root” /target:”$/target branch root”</code></p>
<p>Please note that in order for the command to work correctly you must be in the root directory of the target branch.  So once you open up the command line utility you have to just “cd” to the correct directory.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tcscblog.com/2012/01/23/team-foundation-server-unshelving-another-user%e2%80%99s-changes-across-branches/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Insert JavaScript into a Content Editor Web Part (CEWP)</title>
		<link>http://www.tcscblog.com/2012/01/17/insert-javascript-into-a-content-editor-web-part-cewp/</link>
		<comments>http://www.tcscblog.com/2012/01/17/insert-javascript-into-a-content-editor-web-part-cewp/#comments</comments>
		<pubDate>Tue, 17 Jan 2012 20:21:34 +0000</pubDate>
		<dc:creator>Adam Preston</dc:creator>
				<category><![CDATA[Development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[SharePoint 2010]]></category>

		<guid isPermaLink="false">http://www.tcscblog.com/?p=398</guid>
		<description><![CDATA[In the 2007 version of SharePoint, we had the Source Editor included in the Content Editor Web Part (CEWP) as our way of inputting JavaScript directly onto a page. The process on how to do this has changed a little &#8230; <a href="http://www.tcscblog.com/2012/01/17/insert-javascript-into-a-content-editor-web-part-cewp/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>In the 2007 version of SharePoint, we had the Source Editor included in the Content Editor Web Part (CEWP) as our way of inputting JavaScript directly onto a page. The process on how to do this has changed a little bit in the new 2010 version. Follow below on how to successfully perform the same task.
</p>
<p>Instead of having a Source Editor to directly paste in our code, we need to first create a simple text file and save our code there. Once saved, upload that file to SharePoint. I am using the Site Assets library for this demo and a JavaScript that displays today&#8217;s date. After you have uploaded the file, right click on the file and select Copy Shortcut.
</p>
<p><img src="http://www.tcscblog.com/wp-content/uploads/2011/01/011111_2019_InsertJavaS1.png" alt=""/>
	</p>
<p><img src="http://www.tcscblog.com/wp-content/uploads/2011/01/011111_2019_InsertJavaS2.png" alt=""/>
	</p>
<p>Now, go to your desired page and put the page in edit mode. Add in the <strong>Content Editor Web Part</strong> located under the <strong>Media and Content</strong> category. Once added select the web part and use the ribbon UI to navigate to the Web Part Properties screen.
</p>
<p><img src="http://www.tcscblog.com/wp-content/uploads/2011/01/011111_2019_InsertJavaS3.png" alt=""/>
	</p>
<p><img src="http://www.tcscblog.com/wp-content/uploads/2011/01/011111_2019_InsertJavaS4.png" alt=""/>
	</p>
<p>On the web part properties screen, paste in the URL link to your uploaded JavaScript file. Click <strong>OK</strong> on the properties screen and, if your JavaScript is valid, it should display the desired results! Simple and easy!
</p>
<p><img src="http://www.tcscblog.com/wp-content/uploads/2011/01/011111_2019_InsertJavaS5.png" alt=""/>
	</p>
<p><img src="http://www.tcscblog.com/wp-content/uploads/2011/01/011111_2019_InsertJavaS6.png" alt=""/></p>
]]></content:encoded>
			<wfw:commentRss>http://www.tcscblog.com/2012/01/17/insert-javascript-into-a-content-editor-web-part-cewp/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Add Top Link Bar Inheritance using PowerShell for SharePoint 2010</title>
		<link>http://www.tcscblog.com/2012/01/01/add-top-link-bar-inheritance-using-powershell-for-sharepoint-2010/</link>
		<comments>http://www.tcscblog.com/2012/01/01/add-top-link-bar-inheritance-using-powershell-for-sharepoint-2010/#comments</comments>
		<pubDate>Sun, 01 Jan 2012 14:53:37 +0000</pubDate>
		<dc:creator>Adam Preston</dc:creator>
				<category><![CDATA[Administration]]></category>
		<category><![CDATA[PowerShell]]></category>

		<guid isPermaLink="false">http://www.tcscblog.com/2012/01/01/add-top-link-bar-inheritance-using-powershell-for-sharepoint-2010/</guid>
		<description><![CDATA[I would like to kick off the New Year with perhaps my shortest blog entry for 2012! I had a client that created several subsites without selecting to use the same navigation as its parent. The decision was later made &#8230; <a href="http://www.tcscblog.com/2012/01/01/add-top-link-bar-inheritance-using-powershell-for-sharepoint-2010/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>I would like to kick off the New Year with perhaps my shortest blog entry for 2012!
</p>
<p>I had a client that created several subsites without selecting to use the same navigation as its parent. The decision was later made to add this back in order to provide some consistency throughout the environment. To easily resolve this, open up the SharePoint 2010 Management Shell and perform the following:
</p>
<p><strong>For one site:<br />
</strong></p>
<p>$web = Get-SPWeb -Identity <a href="http://portal.company.com">http://portal.company.com</a>
	</p>
<p>$web.Navigation.UseShared = $true
</p>
<p><strong>For every site in the Site Collection:<br />
</strong></p>
<p>Get-SPSite -Identity <a href="http://portal.company.com">http://portal.company.com</a> | Get-SPWeb -Limit All | %{$_.Navigation.UseShared=$true}
</p>
<p>Yes, it&#8217;s THAT simple!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tcscblog.com/2012/01/01/add-top-link-bar-inheritance-using-powershell-for-sharepoint-2010/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Developing a Webpart with a Dynamic UI</title>
		<link>http://www.tcscblog.com/2011/12/22/developing-a-webpart-with-a-dynamic-ui/</link>
		<comments>http://www.tcscblog.com/2011/12/22/developing-a-webpart-with-a-dynamic-ui/#comments</comments>
		<pubDate>Thu, 22 Dec 2011 16:26:32 +0000</pubDate>
		<dc:creator>Mike Polen</dc:creator>
				<category><![CDATA[.Net]]></category>
		<category><![CDATA[Development]]></category>
		<category><![CDATA[JavaScript]]></category>
		<category><![CDATA[JQuery]]></category>
		<category><![CDATA[SharePoint 2007]]></category>
		<category><![CDATA[SharePoint 2010]]></category>

		<guid isPermaLink="false">http://www.tcscblog.com/?p=1954</guid>
		<description><![CDATA[One of the problems I run into when writing web parts that display SharePoint data is when the UI is dependent on dynamic content. In the past I have generated the HTML on the server-side. This works but it not the &#8230; <a href="http://www.tcscblog.com/2011/12/22/developing-a-webpart-with-a-dynamic-ui/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>One of the problems I run into when writing web parts that display SharePoint data is when the UI is dependent on dynamic content. In the past I have generated the HTML on the server-side. This works but it not the best solution as C# is not the best language to code HTML in. Also <a href="http://en.wikipedia.org/wiki/Separation_of_concerns">separation of concerns</a>  is an important principle to me and I want my UI separated from my server-side logic so that server changes are isolated from UI changes and vice versa. The the solution I came up with utilized several different technologies and has shown to be flexible and robust to changes.</p>
<p>The high level approach is:</p>
<ul>
<li>Use server-side to collect SharePoint information</li>
<li>Use <a href="http://james.newtonking.com/pages/json-net.aspx">Json.NET</a> to turn the List into JSON</li>
<li>Use <a href="http://jqueryui.com/demos/tabs/">jQuery UI Tabs</a></li>
<li>Use <a href="https://github.com/BorisMoore/jsrender">jsrender </a>templates to generate HTML from JSON</li>
</ul>
<p>For my particular web part I was reading information from different lists and placing the contents into a generic list based on the Category (also sourced by a list). The SharePoint information was collected, sorted and trimmed to a customizable limit. Next it was made into JSON and placed on the control as a JavaScript variable. The server-side code was simple:</p>
<blockquote><p>Listcategories = GetNewsByCategory();<br />
litJsonDat.Text = JsonConvert.SerializeObject(categories);</p></blockquote>
<p>Each category contains &#8220;Listnews&#8221; that caused the JSON to be two levels deep. The first level was the category and the second level was news items by category.</p>
<p>My project required the ability to use tabs in the UI to display different content. I chose to use jQuery UI Tabs as I believe in reusing working solutions whenever possible. jQuery Tabs requires the following HTML:</p>
<blockquote><p>&lt;div id=&#8221;tabs&#8221;&gt;<br />
&lt;ul&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#tabs-1&#8243;&gt;Tab 1&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#tabs-2&#8243;&gt;Tab 2&lt;/a&gt;&lt;/li&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#tabs-3&#8243;&gt;Tab 3&lt;/a&gt;&lt;/li&gt;<br />
&lt;/ul&gt;<br />
&lt;div id=&#8221;tabs-1&#8243;&gt;Tab 1 content&lt;/div&gt;<br />
&lt;div id=&#8221;tabs-2&#8243;&gt;Tab 2 content&lt;/div&gt;<br />
&lt;div id=&#8221;tabs-3&#8243;&gt;Tab 3 content&lt;/div&gt;<br />
&lt;/div&gt;</p></blockquote>
<p>And the following script:</p>
<blockquote><p> $( &#8220;#tabs&#8221; ).tabs();</p></blockquote>
<p>In order to generate the tabs dynamically I chose to use jsrender in order to use HTML templates driven by JSON data. My tab list template looks like:</p>
<blockquote><p><script id="<span class=" type="text/javascript">// <![CDATA[
tabTemplate</span>" type="text/x-jquery-tmpl"></body>
// ]]&gt;</script>&lt;script id=&#8221;tabTemplate&#8221; type=&#8221;text/x-jquery-tmpl&#8221;&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#tabs-{{=$itemNumber}}&#8221;&gt;{{=name}}&lt;/a&gt;&lt;/li&gt;<br />
&lt;/script&gt;</p></blockquote>
<p>&#8220;{{=&#8221; starts a template variable and &#8220;}}&#8221; ends it. &#8220;$itemNumber&#8221; is a variable kept by jsrender that starts at 1 and auto increments for each element. &#8220;{{=name}}&#8221; tells the template to look for &#8220;name&#8221; in the JSON element.</p>
<p>To utilize the template first create a destination:</p>
<blockquote><p>&lt;div id=&#8221;tabDiv&#8221;&gt;&lt;ul id=&#8221;tabList&#8221;&gt;&lt;/ul&gt;&lt;/div&gt;</p></blockquote>
<p>Then call render like so:</p>
<blockquote><p>$(&#8220;#tabList&#8221;).html($(&#8220;#tabTemplate&#8221;).render(tabData));</p></blockquote>
<p>For the content I needed a template that dove one level deeper and this is easily supported in jsrender with &#8220;each&#8221;. Here is a simplified version of my template:</p>
<blockquote><p><script id="<span class=" type="text/javascript">// <![CDATA[
tabDivTemplate</span>" type="text/x-jquery-tmpl"></body>
// ]]&gt;</script>&lt;script id=&#8221;tabDivTemplate&#8221; type=&#8221;text/x-jquery-tmpl&#8221;&gt;<br />
&lt;div id=&#8221;tabs-{{=$itemNumber}}&#8221;&gt;<br />
&lt;div id=&#8221;divNewsDetails-tabs-{{=$itemNumber}}&#8221;&gt;<br />
{{each news tmpl=&#8221;#newsDetailsTemplate&#8221;}}<br />
&lt;/div&gt;<br />
&lt;/script&gt;</p></blockquote>
<p>And here is the newsDetailsTemplate:</p>
<blockquote><p>&lt;script id=&#8221;newsDetailsTemplate&#8221; type=&#8221;text/x-jquery-tmpl&#8221;&gt;<br />
&lt;div id=&#8221;categoryviewer-news-img-div&#8221;&gt;<br />
&lt;img id=&#8221;categoryviewer-news- img&#8221;<br />
src=&#8221;{{=thumbNailImage}}&#8221;&gt;<br />
&lt;/div&gt;<br />
&lt;div id=&#8221;categoryviewer-news-section&#8221;&gt;<br />
&lt;div id=&#8221;categoryviewer-news-title-tag&#8221;&gt;<br />
&lt;div id=&#8221;categoryviewer-news-title&#8221;&gt;{{=title}}&lt;/div&gt;<br />
&lt;div id=&#8221;categoryviewer-news-tag&#8221;&gt;{{=tagLine}}&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/script&gt;</p></blockquote>
<p>The destination is in the same div as the tabList but needs to be appended for the jQuery UI Tabs to work so the script is:</p>
<blockquote><p>$(&#8220;#tabDiv&#8221;).append($(&#8220;#tabDivTemplate&#8221;).render(tabData));</p></blockquote>
<p>When you wrap this all together you get the following in the control (I have example JSON data inserted):</p>
<blockquote><p>&lt;link type=&#8221;text/css&#8221; href=&#8221;/_layouts/TCSC.SharePoint.WebParts.WebPartName/jquery-ui-1.8.16.custom.css&#8221; rel=&#8221;stylesheet&#8221; /&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;/_layouts/TCSC.SharePoint.WebParts.WebPartName/jquery-1.6.2.min.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;/_layouts/TCSC.SharePoint.WebParts.WebPartName/jquery-ui-1.8.16.custom.min.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script type=&#8221;text/javascript&#8221; src=&#8221;/_layouts/TCSC.SharePoint.WebParts.WebPartName/jsrender.js&#8221;&gt;&lt;/script&gt;<br />
&lt;script id=&#8221;tabTemplate&#8221; type=&#8221;text/x-jquery-tmpl&#8221;&gt;<br />
&lt;li&gt;&lt;a href=&#8221;#tabs-{{=$itemNumber}}&#8221;&gt;{{=name}}&lt;/a&gt;&lt;/li&gt;<br />
&lt;/script&gt;<br />
&lt;script id=&#8221;tabDivTemplate&#8221; type=&#8221;text/x-jquery-tmpl&#8221;&gt;<br />
&lt;div id=&#8221;tabs-{{=$itemNumber}}&#8221;&gt;<br />
&lt;div id=&#8221;divNewsDetails-tabs-{{=$itemNumber}}&#8221;&gt;<br />
{{each news tmpl=&#8221;#newsDetailsTemplate&#8221;}}<br />
&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/script&gt;<br />
&lt;script id=&#8221;newsDetailsTemplate&#8221; type=&#8221;text/x-jquery-tmpl&#8221;&gt;<br />
&lt;div id=&#8221;categoryviewer-news-img-div&#8221;&gt;<br />
&lt;img id=&#8221;categoryviewer-news-img&#8221; src=&#8221;{{=thumbNailImage}}&#8221;&gt;&lt;/img&gt;<br />
&lt;/div&gt;<br />
&lt;div id=&#8221;categoryviewer-news-section&#8221;&gt;<br />
&lt;div id=&#8221;categoryviewer-news-title-tag&#8221;&gt;<br />
&lt;div id=&#8221;categoryviewer-news-title&#8221;&gt;{{=title}}&lt;/div&gt;<br />
&lt;div id=&#8221;categoryviewer-news-tag&#8221;&gt;{{=tagLine}}&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/div&gt;<br />
&lt;/script&gt;<br />
&lt;div id=&#8221;tabDiv&#8221;&gt;&lt;ul id=&#8221;tabList&#8221;&gt;&lt;/ul&gt;&lt;/div&gt;<br />
&lt;script type=&#8221;text/javascript&#8221;&gt;<br />
var tabData=[{"name":"Tab 1","news" :[{"title":"Tab 1 news","tagLine":"This is news for tab 1","thumbNailImage":""}]},{&#8220;name&#8221;:&#8221;Tab 2&#8243;, &#8220;news&#8221; :[{"title":"Tab 2 news","tagLine":"This is news for tab 2","thumbNailImage":""}]},{&#8220;name&#8221;:&#8221;Tab 3&#8243;, &#8220;news&#8221; :[{"title":"Tab 3 news","tagLine":"This is news for tab 3","thumbNailImage":""}]}];<br />
$(&#8220;#tabList&#8221;).html($(&#8220;#tabTemplate&#8221;).render(tabData));<br />
$(&#8220;#tabDiv&#8221;).append($(&#8220;#tabDivTemplate&#8221;).render(tabData));<br />
$(document).ready(function(){<br />
$(&#8220;#tabDiv&#8221;).tabs();<br />
});<br />
&lt;/script&gt;</p></blockquote>
<p>This results in a nice tab interface with dynamic content that is both modular and fairly easy to change. The UI is seperated from the server side and the coupling is a JSON object which is dictated by the underlying business objects. This method has worked well for me and I hope others improve upon it.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tcscblog.com/2011/12/22/developing-a-webpart-with-a-dynamic-ui/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>ASP.NET Dynamic HTML with HTML Controls</title>
		<link>http://www.tcscblog.com/2011/12/12/asp-net-dynamic-html-with-html-controls/</link>
		<comments>http://www.tcscblog.com/2011/12/12/asp-net-dynamic-html-with-html-controls/#comments</comments>
		<pubDate>Mon, 12 Dec 2011 22:32:08 +0000</pubDate>
		<dc:creator>Rick Matherly</dc:creator>
				<category><![CDATA[ASP.NET]]></category>
		<category><![CDATA[HTML Controls]]></category>

		<guid isPermaLink="false">http://www.tcscblog.com/?p=1940</guid>
		<description><![CDATA[There are many times that you need to process a data list and generate HTML to output to an ASP.NET page. Most of the time, a Repeater is the best choice for this, but sometimes using a Repeater is not &#8230; <a href="http://www.tcscblog.com/2011/12/12/asp-net-dynamic-html-with-html-controls/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There are many times that you need to process a data list and generate HTML to output to an ASP.NET page. Most of the time, a Repeater is the best choice for this, but sometimes using a Repeater is not practical because the HTML has too many levels or is built with too many conditionals. In these cases, you could use a StringBuilder and output the result to a Literal control, but working with strings can be error prone.  My preferred method to add a Placeholder control to the page and then just add Controls to its Controls collection in the code behind. </p>
<p>This works out well if you want to use web controls, but not if you want to use HTML controls. One of the goals with web controls was to make the properties more consistent accross controls, but if you are familiar with HTML, then using the HTML controls might be more natural because the properties match the attributes you are already familiar with.</p>
<p>The issue with HTML Controls is that they are not as friendly to work with. For many elements, such as divs, you will have to use the HtmlGenericControl class. Although web controls have a property for CssClass, this is not available for HTML controls.  If you want to add a new div control with a CSS class, you will end up with something like this:</p>
<p style="color: #222; padding: 20px; background-color: #f7f7f7;">
var divContainer = new HtmlGenericControl(&#8220;div&#8221;);<br />
divContainer.Attributes.Add(&#8220;class&#8221;, &#8220;div-class&#8221;);
</p>
<p>To improve on this syntax, I added a derived control with a CSSClass property:</p>
<p style="color: #222; padding: 20px; background-color: #f7f7f7;">
public class HtmlClassedControl : HtmlGenericControl<br />
{<br />
&nbsp;&nbsp;public HtmlClassedControl(string tag) : base(tag)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;}<br />
&nbsp;&nbsp;<br />
&nbsp;&nbsp;public string CssClass<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;&nbsp;&nbsp;get { return GetAttribute(&#8220;class&#8221;); }<br />
&nbsp;&nbsp;&nbsp;&nbsp;set { Attributes.Add(&#8220;class&#8221;, value); }<br />
&nbsp;&nbsp;}<br />
}
</p>
<p>Next, I added another derived class for the div control to eliminate the constructor parameter:</p>
<p style="color: #222; padding: 20px; background-color: #f7f7f7;">
public class HtmlDiv : HtmlClassedControl<br />
{<br />
&nbsp;&nbsp;public HtmlDiv() : base(&#8220;div&#8221;)<br />
&nbsp;&nbsp;{<br />
&nbsp;&nbsp;}<br />
}
</p>
<p>With these changes, the sytax becomes:</p>
<p style="color: #222; padding: 20px; background-color: #f7f7f7;">
var divContainer = new HtmlDiv {CssClass = &#8220;div-class&#8221;};
</p>
<p>That may not seem like much of a change, but if you are adding 20 or 30 controls with nesting and looping, it makes a huge difference in readability and maintainabiliy&#8230; not to mention less code to write.  You could easily add classes for other HTML elemnts such as unorderded list, list item, etc.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tcscblog.com/2011/12/12/asp-net-dynamic-html-with-html-controls/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Debugging a T4 Template</title>
		<link>http://www.tcscblog.com/2011/12/08/debugging-a-t4-template/</link>
		<comments>http://www.tcscblog.com/2011/12/08/debugging-a-t4-template/#comments</comments>
		<pubDate>Thu, 08 Dec 2011 17:39:09 +0000</pubDate>
		<dc:creator>Tom Becker</dc:creator>
				<category><![CDATA[.Net]]></category>

		<guid isPermaLink="false">http://www.tcscblog.com/?p=1915</guid>
		<description><![CDATA[T4 templates are extremely useful for generating repetitive code quickly and reliably.  Getting them to produce good code can prove to be tricky for anything less than a trivial example.  If you are having issues, stepping through the template to &#8230; <a href="http://www.tcscblog.com/2011/12/08/debugging-a-t4-template/">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>T4 templates are extremely useful for generating repetitive code quickly and reliably.  Getting them to produce good code can prove to be tricky for anything less than a trivial example.  If you are having issues, stepping through the template to see what is going awry can prove difficult as there is little debugging support right out of the box. </p>
<p>Luckily some methods do exist to add more basic debugging functionality to your template.  MSDN has a <a href="http://msdn.microsoft.com/en-us/library/bb126338.aspx">good article</a> that goes a bit more in depth, but here are the basic steps to get you going. </p>
<h4><strong>Step 1:</strong></h4>
<p>Modify the declaration to enable debugging</p>
<p>&lt;#@ template language=”C#” <strong>debug=”true”</strong> hostspecific=”true” #&gt;</p>
<h4><strong>Step 2:</strong></h4>
<p>Add the following line to launch the debugger. </p>
<p>System.Diagnostics.Debugger.Launch();</p>
<p>You can have this line anywhere in template as long as it is between the scripting braces (&lt;#   #&gt;).</p>
<p>After you have added the line, simply re-run your T4 template and you should see a Visual Studio Just-In-Time debugger window pop up asking if you want to debug the error.  Choose a new instance of VS and you should be able to debug the TT file just as you would in a normal debugging session.</p>
<p>After you have finished debugging and are ready to run your T4 template, don’t forget to set debug back to false, as well as remove the call to the debugger.</p>
]]></content:encoded>
			<wfw:commentRss>http://www.tcscblog.com/2011/12/08/debugging-a-t4-template/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
	</channel>
</rss>

<!-- Dynamic page generated in 1.102 seconds. -->
<!-- Cached page generated by WP-Super-Cache on 2012-02-22 23:34:17 -->

