<?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/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Tom Clarkson</title>
	<atom:link href="http://tqcblog.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://tqcblog.com</link>
	<description>SharePoint, Startups and some other stuff</description>
	<lastBuildDate>Thu, 10 Mar 2011 04:32:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='tqcblog.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Tom Clarkson</title>
		<link>http://tqcblog.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://tqcblog.com/osd.xml" title="Tom Clarkson" />
	<atom:link rel='hub' href='http://tqcblog.com/?pushpress=hub'/>
		<item>
		<title>Fixing Parser Errors in SharePoint</title>
		<link>http://tqcblog.com/2011/02/22/fixing-parser-errors-in-sharepoint/</link>
		<comments>http://tqcblog.com/2011/02/22/fixing-parser-errors-in-sharepoint/#comments</comments>
		<pubDate>Tue, 22 Feb 2011 06:23:52 +0000</pubDate>
		<dc:creator>Tom Clarkson</dc:creator>
				<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://tqcblog.com/?p=232</guid>
		<description><![CDATA[I have been getting the error below quite a lot in my SharePoint development environment, usually after updating a solution package. The only fixes I was able to find by searching referred to mysteriously changed casing on placeholders, which was happening, but didn&#8217;t help in this case. It turns out that this parser error actually [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tqcblog.com&amp;blog=18799009&amp;post=232&amp;subd=tomclarkson&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>I have been getting the error below quite a lot in my SharePoint development environment, usually after updating a solution package.</p>
<p>The only fixes I was able to find by searching referred to mysteriously changed casing on placeholders, which was happening, but didn&#8217;t help in this case.</p>
<p>It turns out that this parser error actually has nothing to do with either parsing or the page being viewed. It can be triggered by just about anything &#8211; in this case it was an error finding the base class for a web part that was never on the page.</p>
<p>The actual error message can be found in the application event log &#8211; nothing useful gets added to the ULS logs.</p>
<h2><em>Parser Error</em></h2>
<p><span style="font-family:Arial,Helvetica,Geneva,SunSans-Regular,sans-serif;"> <strong> Description: </strong>An error occurred during the parsing of  a resource required to service this request.   Please review the  following specific parse error details and modify your source file  appropriately.</span></p>
<p><strong> Parser Error Message: </strong>This page has encountered a critical error. Contact your system administrator if this problem persists.</p>
<p><strong>Source Error:</strong></p>
<table width="100%" bgcolor="#ffffcc">
<tbody>
<tr>
<td>
<pre><span style="color:red;">Line 1:&lt;%@ Page Inherits="Microsoft.SharePoint.Publishing.TemplateRedirectionPage,Microsoft.SharePoint.Publishing,Version=12.0.0.0,Culture=neutral,PublicKeyToken=71e9bce111e9429c" %&gt; &lt;%@ Reference VirtualPath="~TemplatePageUrl" %&gt; &lt;%@ Reference VirtualPath="~masterurl/custom.master" %&gt;&lt;html xmlns:mso="urn:schemas-microsoft-com:office:office" xmlns:msdt="uuid:C2F41010-65B3-11d1-A29F-00AA00C14882"&gt;&lt;head&gt;
</span>Line 2:  &lt;!--[if gte mso 9]&gt;--&gt;
Line 3:&lt;mso:CustomDocumentProperties&gt;
</pre>
</td>
</tr>
</tbody>
</table>
<p><span style="font-family:Arial,Helvetica,Geneva,SunSans-Regular,sans-serif;"><br />
<strong> Source File: </strong> /Pages/Home.aspx<strong> Line: </strong> 1<br />
</span></p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tomclarkson.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tomclarkson.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tomclarkson.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tomclarkson.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tomclarkson.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tomclarkson.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tomclarkson.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tomclarkson.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tomclarkson.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tomclarkson.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tomclarkson.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tomclarkson.wordpress.com/232/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tomclarkson.wordpress.com/232/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tomclarkson.wordpress.com/232/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tqcblog.com&amp;blog=18799009&amp;post=232&amp;subd=tomclarkson&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tqcblog.com/2011/02/22/fixing-parser-errors-in-sharepoint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e46378f30c2abbec6f805c0333db04d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tqc00</media:title>
		</media:content>
	</item>
		<item>
		<title>Developing with Multiple Versions of Visual Studio</title>
		<link>http://tqcblog.com/2011/02/16/developing-with-multiple-versions-of-visual-studio/</link>
		<comments>http://tqcblog.com/2011/02/16/developing-with-multiple-versions-of-visual-studio/#comments</comments>
		<pubDate>Wed, 16 Feb 2011 05:07:41 +0000</pubDate>
		<dc:creator>Tom Clarkson</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://tqcblog.com/?p=223</guid>
		<description><![CDATA[One of the SharePoint projects I am working on involves a Visual Studio 2008 solution that is used across several teams of developers.  I want to use Visual Studio 2010, but converting the projects would cause problems for anyone still using VS2008, and if everyone has to upgrade to VS2010 at the same time it [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tqcblog.com&amp;blog=18799009&amp;post=223&amp;subd=tomclarkson&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>One of the SharePoint projects I am working on involves a Visual Studio 2008 solution that is used across several teams of developers.  I want to use Visual Studio 2010, but converting the projects would cause problems for anyone still using VS2008, and if everyone has to upgrade to VS2010 at the same time it will never happen.</p>
<p>Visual Studio does not support opening projects in multiple versions, and a search only came up with ways to maintain seperate projects, either manually or with some sort of sync process, which seems far too complicated.</p>
<p>Fortunately, it turns out that if the projects are simple enough, you can use them in both VS2008 and VS2010.  It may not work for web apps or test projects, but for class libraries (or WSPBuilder solution projects) you just need to make a couple of manual edits to each project file.</p>
<ul>
<li>Remove the web app guid {349c5851-65df-11da-9384-00065b846f21} from ProjectTypeIds &#8211; this can be useful for adding WebForms designer support to WSPBuilder projects, but isn&#8217;t really necessary.</li>
<li>Change the ToolsVersion attribute on project element to 4.0 &#8211; This tells VS2010 that it is the current version and does not require upgrade, while VS2008 will see the invalid version number and fall back to 3.5 with only a warning.</li>
</ul>
<p>Once the project files are  updated, simply create a new solution file for use in VS2010 and add the existing project files, which should now load without triggering the conversion wizard.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tomclarkson.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tomclarkson.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tomclarkson.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tomclarkson.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tomclarkson.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tomclarkson.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tomclarkson.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tomclarkson.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tomclarkson.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tomclarkson.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tomclarkson.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tomclarkson.wordpress.com/223/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tomclarkson.wordpress.com/223/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tomclarkson.wordpress.com/223/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tqcblog.com&amp;blog=18799009&amp;post=223&amp;subd=tomclarkson&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tqcblog.com/2011/02/16/developing-with-multiple-versions-of-visual-studio/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e46378f30c2abbec6f805c0333db04d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tqc00</media:title>
		</media:content>
	</item>
		<item>
		<title>Precompiled Razor for Shared Views and Mono</title>
		<link>http://tqcblog.com/2011/01/23/precompiled-razor-for-shared-views-and-mono/</link>
		<comments>http://tqcblog.com/2011/01/23/precompiled-razor-for-shared-views-and-mono/#comments</comments>
		<pubDate>Sun, 23 Jan 2011 03:39:22 +0000</pubDate>
		<dc:creator>Tom Clarkson</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[Mono]]></category>

		<guid isPermaLink="false">http://tqcblog.com/?p=206</guid>
		<description><![CDATA[SharePoint isn&#8217;t the only platform I work with where I can&#8217;t quite use ASP.NET MVC 3 out of the box. I also have quite a bit of code on Mono. Mono will probably support MVC 3 at some point, but right now it only almost works &#8211; there is only one line of code that [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tqcblog.com&amp;blog=18799009&amp;post=206&amp;subd=tomclarkson&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>SharePoint isn&#8217;t the only platform I work with where I can&#8217;t quite use ASP.NET MVC 3 out of the box. I also have quite a bit of code on Mono. Mono will probably support MVC 3 at some point, but right now it only almost works &#8211; there is only one line of code that doesn&#8217;t work, but that line gets called at the start of every request.</p>
<p>Since the problem is in finding and parsing the cshtml files, it should be possible to get around the issue with precompiled views and a custom VirtualPathProvider or ViewEngine. As well as getting around issues with Mono, having views precompiled makes it a lot easier to include views in a shared library. I have shared aspx views working with embedded resources and a custom VirtualPathProvider, but there usually end up being some differences between the handling of embedded and regular views.</p>
<p>As a starting point I used Chris van de Steegs code (<a href="http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/">Compile your asp.net mvc Razor views into a seperate dll</a>), though what I ended up with was quite different. The current implementation of BuildManager is one of the places where Mono and .NET are not the same (<a href="http://go-mono.com/forums/#nabble-td3219000">http://go-mono.com/forums/#nabble-td3219000</a>), and there&#8217;s a lot of stuff in that path that is more complex than is necessary in this case.</p>
<p>My solution uses a custom ViewEngine, View and ViewPage base class. My first attempt used a virtual path provider to find compiled views using the standard WebViewPage base class, but even if you have the ViewEngine find the compiled view, WebViewPage calls BuildManager anyway to find layouts and check various things that don&#8217;t need checking when the view is precompiled.</p>
<p>The <a href="https://github.com/tqc/RazorEngine/blob/master/CompiledViews.Mvc/CompiledRazorViewEngine.asax.cs">ViewEngine</a> is fairly simple &#8211; a dictionary maps virtual paths to compiled types and CreateView creates an instance of the appropriate type. The dictionary is populated by finding all types in an assembly that implement ICompiledViewPage and are in a Views namespace.</p>
<p>The <a href="https://github.com/tqc/RazorEngine/blob/master/CompiledViews.Mvc/CompiledViewPageView.cs">IView implementation</a> also doesn&#8217;t do much &#8211; RenderView populates some context objects and calls ExecutePage.</p>
<p>The custom view base class, <a href="https://github.com/tqc/RazorEngine/blob/master/CompiledViews.Mvc/CompiledViewPage.cs">CompiledViewPage</a> does the actual page rendering. It is a subclass of WebViewPage, but I ended up not being able to use that much from the base class due to some inconvenient internal/private fields. It is set up to work as a base class for ViewStart pages, layouts, and regular views. The basic flow for rendering a page is:</p>
<ol>
<li>If there is a ViewStart page, call its execute method and copy its context settings</li>
<li>Call execute on the main page. This will produce a string for the page body and a dictionary mapping section names to actions that will write the content of the section.</li>
<li>Call execute on the layout, which will include calls to RenderSection that run the actions set up by the main page execute method.</li>
</ol>
<p>There are a few things in the code that can be cleaned up, particularly around the handling of writers and helpers. So far it&#8217;s working rather than really good code, but it works for everything I&#8217;ve tried it on (both .NET and Mono) and I&#8217;ll probably improve on it as it gets more real world use.</p>
<p>The other part of the system is generating the code files that will be compiled. I do this with a console app, <a href="https://github.com/tqc/RazorEngine/tree/master/GenerateViewCodeWithMvc">GenerateViewsWithMvc</a>, that is set up as an external tool in Visual Studio to generate code for all cshtml files in a project. It&#8217;s very similar to the one I use for <a href="http://tqcblog.com/2011/01/22/asp-net-mvc-3-razor-views-in-sharepoint/">Razor views in SharePoint</a> &#8211; the main difference is that it uses WebPageRazorHost rather than RazorEngineHost so that it can use sections. It also uses a dynamic type parameter rather than an untyped base class for untyped views because I can&#8217;t have the base type extend both the typed and untyped versions of WebPageView without duplicating all the code.</p>
<p>The external tool settings are:</p>
<ul>
<li>Command: GenerateViewCodeWithMvc.exe</li>
<li>Arguments (base class for views): CompiledViews.CompiledViewPage</li>
<li>Initial Directory: $(ProjectDir)</li>
</ul>
<p>Using the compiled views in a web app requires a few lines in Application_Start:</p>
<pre class="brush: plain;">
            ViewEngines.Engines.Clear();
            var engine = new CompiledRazorViewEngine();
            CompiledRazorViewEngine.RegisterViewAssembly(typeof(CompiledRazorViewEngine).Assembly);
            CompiledRazorViewEngine.RegisterViewAssembly(typeof(CompiledViews.Mvc3Test.Views._ViewStart).Assembly);
            ViewEngines.Engines.Add(engine);
</pre>
<p>The first RegisterViewAssembly call adds views from a shared library and the second adds the views in the current assembly. If the same view exists in both assemblies, the last one added will be used. This code removes all other view engines &#8211; it should be possible to use it with other view engines, though there will obviously be some conflicts if the other view engine also looks for cshtml files in the Views folder.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tomclarkson.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tomclarkson.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tomclarkson.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tomclarkson.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tomclarkson.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tomclarkson.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tomclarkson.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tomclarkson.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tomclarkson.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tomclarkson.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tomclarkson.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tomclarkson.wordpress.com/206/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tomclarkson.wordpress.com/206/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tomclarkson.wordpress.com/206/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tqcblog.com&amp;blog=18799009&amp;post=206&amp;subd=tomclarkson&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tqcblog.com/2011/01/23/precompiled-razor-for-shared-views-and-mono/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e46378f30c2abbec6f805c0333db04d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tqc00</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET MVC Controller Actions in SharePoint</title>
		<link>http://tqcblog.com/2011/01/23/asp-net-mvc-controller-actions-in-sharepoint/</link>
		<comments>http://tqcblog.com/2011/01/23/asp-net-mvc-controller-actions-in-sharepoint/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 23:21:57 +0000</pubDate>
		<dc:creator>Tom Clarkson</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://tqcblog.com/?p=197</guid>
		<description><![CDATA[Having got Razor views working in SharePoint, I needed a better way to use them &#8211; displaying the view is three lines of fairly clean code, but it&#8217;s surrounded by the all the event handler methods you need in a web forms page or control. It turns out that with the right code in the [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tqcblog.com&amp;blog=18799009&amp;post=197&amp;subd=tomclarkson&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Having got <a href="http://tqcblog.com/2011/01/22/asp-net-mvc-3-razor-views-in-sharepoint/">Razor views working in SharePoint</a>, I needed a better way to use them &#8211; displaying the view is three lines of fairly clean code, but it&#8217;s surrounded by the all the event handler methods you need in a web forms page or control.</p>
<p>It turns out that with the right code in the base class, a web part can look a lot like an ASP.NET MVC controller.</p>
<pre class="brush: plain;">
    public class ExampleWebPart : MvcWebPart
    {
        protected override ActionResult Get()
        {
            var m = new DocSection()
            {
                Title = &quot;Test Model&quot;
            };
            return View(new DocView(), m);
        }
    }
</pre>
<p>The ActionResult/ViewResult classes have a similar interface to the ones in ASP.NET MVC, though they are quite simple so far. The key functionality is in the Execute() method, which actually renders the view. The standard ASP.NET ViewResult writes to the Response, but since this is happening inside a SharePoint page we need to add the content as a control on  the page instead.</p>
<pre class="brush: plain;">
public override void Execute()
 {
 View.Model = Model;
 View.Execute();
 ParentControl.Controls.Add(new LiteralControl(View.Result));
 }
</pre>
<p>Getting an ActionResult From the subclass and executing it happens in CreateChildControls &#8211; I&#8217;m not totally sure that is the best place for it, but it seems to be working well so far.</p>
<pre class="brush: plain;">
        protected override void CreateChildControls()
        {
            if (!_error)
            {
                try
                {
                    base.CreateChildControls();
                    var r = Get();
                    r.Execute();
                }
                catch (Exception ex)
                {
                    HandleException(ex);
                }
            }
        }
</pre>
<p> The full code can be found on <a href="https://github.com/tqc/RazorEngine/tree/master/CompiledViews.SharePoint">github</a>.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tomclarkson.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tomclarkson.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tomclarkson.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tomclarkson.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tomclarkson.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tomclarkson.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tomclarkson.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tomclarkson.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tomclarkson.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tomclarkson.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tomclarkson.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tomclarkson.wordpress.com/197/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tomclarkson.wordpress.com/197/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tomclarkson.wordpress.com/197/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tqcblog.com&amp;blog=18799009&amp;post=197&amp;subd=tomclarkson&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tqcblog.com/2011/01/23/asp-net-mvc-controller-actions-in-sharepoint/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e46378f30c2abbec6f805c0333db04d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tqc00</media:title>
		</media:content>
	</item>
		<item>
		<title>ASP.NET MVC 3 Razor Views in SharePoint</title>
		<link>http://tqcblog.com/2011/01/22/asp-net-mvc-3-razor-views-in-sharepoint/</link>
		<comments>http://tqcblog.com/2011/01/22/asp-net-mvc-3-razor-views-in-sharepoint/#comments</comments>
		<pubDate>Sat, 22 Jan 2011 11:59:37 +0000</pubDate>
		<dc:creator>Tom Clarkson</dc:creator>
				<category><![CDATA[.NET]]></category>
		<category><![CDATA[SharePoint]]></category>

		<guid isPermaLink="false">http://tqcblog.com/?p=191</guid>
		<description><![CDATA[ASP.NET MVC 3 has just been released, and I really like the new Razor syntax for views. However, I work with SharePoint, which is solidly based on WebForms and .NET 3.5. Razor requires .NET 4, and while you can host WebForms MVC pages in _layouts, it&#8217;s an ugly hack that gives you the worst features [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tqcblog.com&amp;blog=18799009&amp;post=191&amp;subd=tomclarkson&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>ASP.NET MVC 3 has just been released, and I really like the new Razor syntax for views. However, I work with SharePoint, which is solidly based on WebForms and .NET 3.5. Razor requires .NET 4, and while you can host WebForms MVC pages in _layouts, it&#8217;s an ugly hack that gives you the worst features of both systems.</p>
<p>Razor is internally quite different from WebForms, and the core functionality doesn&#8217;t actually require MVC, so it should be possible to use it in a system that can&#8217;t use MVC.</p>
<p>My first attempt to make Razor work under SharePoint was to see if it would compile without .NET 4. That didn&#8217;t work, but I did notice that most of the dependencies on .NET 4 are in parsing the templates &#8211; you can&#8217;t build cshtml files without .NET 4, but the generated code doesn&#8217;t require anything special.</p>
<p>Starting with the code from <a href="http://razorengine.codeplex.com/">http://razorengine.codeplex.com/</a> I was able to convert a cshtml file into a cs file that can be compiled in a .NET 3.5 project. My version of the code is at <a href="https://github.com/tqc/RazorEngine">https://github.com/tqc/RazorEngine</a>.</p>
<p>RazorEngine came pretty close to what I needed, only requiring fairly minor changes:</p>
<ul>
<li>Add methods to return the generated source code rather than compiling and running it</li>
<li>Copy the template base classes into a .NET 3.5 library (RazorEngine.Run). This meant removing support for dynamic objects, but apart from that the code doesn&#8217;t require the latest version.</li>
</ul>
<p>I set up a console app (GenerateViewCode) that will generate code files for all cshtml files in a project. I considered using a single file generator, but a console app is easier to debug and more likely to work properly on a build server. It is intended to be set up as an external tool in Visual Studio:</p>
<ul>
<li>Command: GenerateViewCode.exe</li>
<li>Arguments (base class for views): RazorEngine.Templating.TemplateBase</li>
<li>Initial Directory: $(ProjectDir)</li>
</ul>
<p>After you run the tool on a project containing cshtml files and include the generated code in the project, you will be able to render the view from your code:</p>
<pre class="brush: plain;">
var view = new TestViewLibrary.Views.Shared.DocView()
view.Model = newTestViewLibrary.Models.DocSection();
 view.Execute();
 ParentControl.Controls.Add(new LiteralControl(View.Result));
</pre>
<p>This replaces either trying to build html in code (with code that looks a lot like the generated output from Razor) or finding and loading a usercontrol in _layouts. </p>
<p>MVC isn&#8217;t just about the view though &#8211; more on that shortly.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/tomclarkson.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/tomclarkson.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/tomclarkson.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/tomclarkson.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/tomclarkson.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/tomclarkson.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/tomclarkson.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/tomclarkson.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/tomclarkson.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/tomclarkson.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/tomclarkson.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/tomclarkson.wordpress.com/191/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/tomclarkson.wordpress.com/191/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/tomclarkson.wordpress.com/191/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=tqcblog.com&amp;blog=18799009&amp;post=191&amp;subd=tomclarkson&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://tqcblog.com/2011/01/22/asp-net-mvc-3-razor-views-in-sharepoint/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/6e46378f30c2abbec6f805c0333db04d?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">tqc00</media:title>
		</media:content>
	</item>
	</channel>
</rss>
