<?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>In search of perfection... &#187; admin</title>
	<atom:link href="http://agilefutures.com/index.php/author/admin/feed/" rel="self" type="application/rss+xml" />
	<link>http://agilefutures.com</link>
	<description>Illegitimi Non Carborundum</description>
	<lastBuildDate>Sun, 23 Aug 2009 10:23:35 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Windows 7 &amp; .NET 4.0 Beta 1</title>
		<link>http://agilefutures.com/index.php/2009/08/windows-7-net-4-0-beta-1/</link>
		<comments>http://agilefutures.com/index.php/2009/08/windows-7-net-4-0-beta-1/#comments</comments>
		<pubDate>Sun, 23 Aug 2009 10:23:35 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://agilefutures.com/index.php/2009/08/windows-7-net-4-0-beta-1/</guid>
		<description><![CDATA[I upgraded to Windows 7 today and failed to Uninstall .NET 4.0 and VS2010 BETA 1. This left me with non working SQL Management Studio (2005 &#38; 2008) with the error “Microsoft SQL Management Studio Package failed to load” It also screwed up all my Red Gate software and VS2010. Then I found out you [...]]]></description>
			<content:encoded><![CDATA[<p>I upgraded to Windows 7 today and failed to Uninstall .NET 4.0 and VS2010 BETA 1. This left me with non working SQL Management Studio (2005 &amp; 2008) with the error “Microsoft SQL Management Studio Package failed to load”    </p>
<p>It also screwed up all my Red Gate software and VS2010. Then I found out you should install Windows 7 after removing .NET 4.0 BETA 1 and Visual Studio other wise you will have to flatten your PC and do a fresh install as the .NET Framework is broken and unfixable. Not really true. I found this worked for me.</p>
<p>Remove .NET 4.0 BETA 1</p>
<p><strong>For x86 OS:      <br /></strong>    <br />cmd /c &quot;msiexec /x {19BD09BF-3BBD-3663-A5ED-50B6B2B07E42} /qb&quot;     <br />cmd /c &quot;msiexec /x {1DF6A8F6-5048-323F-8758-DA533CE0F07E} /qb&quot;     </p>
<p><strong>For x64 OS:      </p>
<p></strong>cmd /c &quot;msiexec /x {175D5555-EE49-3033-99AF-BC1E206223FD} /qb&quot;     <br />cmd /c &quot;msiexec /x {13B27C82-19BA-3494-9420-F932B40673CA} /qb&quot;</p>
<p>Then</p>
<ul>
<li>Reboot </li>
<li>Uninstall Visual Studio 2010 and its redistributables </li>
<li>Reboot </li>
<li>Install .NET 4.0 </li>
<li>Reboot </li>
<li>Install Visual 2010</li>
</ul>
<p>Links to this :-</p>
<p><a title="http://www.microsoft.com/downloads/details.aspx?familyid=EE2118CC-51CD-46AD-AB17-AF6FFF7538C9&amp;displaylang=en#filelist" href="http://www.microsoft.com/downloads/details.aspx?familyid=EE2118CC-51CD-46AD-AB17-AF6FFF7538C9&amp;displaylang=en#filelist" target="_blank">Download .NET 4.0 Beta 1</a>    <br /><a title="http://social.msdn.microsoft.com/Forums/en-US/netfxsetup/thread/a5d827d7-05b4-41b9-9565-e9e4abb12e66" href="http://social.msdn.microsoft.com/Forums/en-US/netfxsetup/thread/a5d827d7-05b4-41b9-9565-e9e4abb12e66" target="_blank">MSDN Forums where I found above info.</a>    <br /><a title="http://www.hanselman.com/blog/VistaUsersUninstallVisualStudio2010Beta1BeforeUpgradingToWindows7.aspx" href="http://www.hanselman.com/blog/VistaUsersUninstallVisualStudio2010Beta1BeforeUpgradingToWindows7.aspx" target="_blank">Hanselman &#8211; Before Upgrading To Windows 7</a></p>
<p>Now I can wait until I get an SSD drive before I do a clean install <img src='http://agilefutures.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' /> .</p>
]]></content:encoded>
			<wfw:commentRss>http://agilefutures.com/index.php/2009/08/windows-7-net-4-0-beta-1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Don&#8217;t buy Norton 360</title>
		<link>http://agilefutures.com/index.php/2009/07/dont-buy-norton-360/</link>
		<comments>http://agilefutures.com/index.php/2009/07/dont-buy-norton-360/#comments</comments>
		<pubDate>Wed, 01 Jul 2009 17:46:25 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Uncategorized]]></category>

		<guid isPermaLink="false">http://agilefutures.com/index.php/2009/07/dont-buy-norton-360/</guid>
		<description><![CDATA[I don’t normally rant on this blog, but don’t buy this product it’s rubbish. It slows down you pc to a crawl, takes up loads of resources, crashes trying to backup your data. Last time I ever spend money on Symantec software. p.s. Can’t even attempt to get a refund. Update I have just uninstalled [...]]]></description>
			<content:encoded><![CDATA[<p>I don’t normally rant on this blog, but don’t buy this product it’s rubbish. It slows down you pc to a crawl, takes up loads of resources, crashes trying to backup your data. Last time I ever spend money on Symantec software.</p>
<p>p.s. Can’t even attempt to get a refund.</p>
<p><strong>Update</strong></p>
<p>I have just uninstalled it and quite shocked how much quicker my computer is…… </p>
]]></content:encoded>
			<wfw:commentRss>http://agilefutures.com/index.php/2009/07/dont-buy-norton-360/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>ActionImage – ASP.NET MVC</title>
		<link>http://agilefutures.com/index.php/2009/06/actionimage-aspnet-mvc/</link>
		<comments>http://agilefutures.com/index.php/2009/06/actionimage-aspnet-mvc/#comments</comments>
		<pubDate>Fri, 12 Jun 2009 12:02:51 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[ActionImage]]></category>
		<category><![CDATA[ActionLink]]></category>
		<category><![CDATA[HtmlHelpers]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://agilefutures.com/index.php/2009/06/actionimage-aspnet-mvc/</guid>
		<description><![CDATA[I was in the middle of doing some grid work using the MVC Contrib UI Grid and need an image column. It was a bit messy and a struggle. Turns out there is not a ActionImage helper that behaves like ActionLink. There are plenty of quick hacks about but I wanted some that behaves the [...]]]></description>
			<content:encoded><![CDATA[<p>I was in the middle of doing some grid work using the MVC Contrib UI Grid and need an image column. It was a bit messy and a struggle. Turns out there is not a <strong>ActionImage</strong> helper that behaves like <strong>ActionLink</strong>. There are plenty of quick hacks about but I wanted some that behaves the same as ActionLink with the same overloads and some extra bits.</p>
<p>It supports all the normal overloads that ActionLink provides in <strong>System.Web.Mvc.Html</strong> and the generic versions from <strong>Microsoft.Web.Mvc.Html</strong>. It also support html attributes for both the anchor tag and the image tag.</p>
<p>Also one thing the Generic version of ActionLink does not have is the ability to specify additional route values as well as the action parameters. <strong>ActionImage </strong>supports the merging of the action parameters and additional route values.</p>
<p>Any suggestions, improvements, fixes, are always welcome. </p>
<p>Regards Tobi.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq.Expressions</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Routing</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Microsoft.Web.Mvc.Internal</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> GMS.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Mvc</span>.<span style="color: #0000FF;">Html</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">class</span> HtmlHelpers
    <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">string</span> actionName<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> htmlHelper.<span style="color: #0000FF;">ActionImage</span><span style="color: #000000;">&#40;</span>imageUrl, linkText, actionName, <span style="color: #0600FF;">null</span>, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">string</span> actionName, <span style="color: #FF0000;">object</span> routeValues<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> htmlHelper.<span style="color: #0000FF;">ActionImage</span><span style="color: #000000;">&#40;</span>imageUrl, linkText, actionName, <span style="color: #0600FF;">null</span>, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span>routeValues<span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">string</span> actionName, <span style="color: #FF0000;">string</span> controllerName<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> htmlHelper.<span style="color: #0000FF;">ActionImage</span><span style="color: #000000;">&#40;</span>imageUrl, linkText, actionName, controllerName, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">string</span> actionName, RouteValueDictionary routeValues<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> htmlHelper.<span style="color: #0000FF;">ActionImage</span><span style="color: #000000;">&#40;</span>imageUrl, linkText, actionName, <span style="color: #0600FF;">null</span>, routeValues, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">string</span> actionName, <span style="color: #FF0000;">object</span> routeValues, <span style="color: #FF0000;">object</span> htmlanchorAttributes<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> htmlHelper.<span style="color: #0000FF;">ActionImage</span><span style="color: #000000;">&#40;</span>imageUrl, linkText, actionName, <span style="color: #0600FF;">null</span>, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span>routeValues<span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span>htmlanchorAttributes<span style="color: #000000;">&#41;</span>, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">string</span> actionName, RouteValueDictionary routeValues, IDictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> htmlanchorAttributes, IDictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> htmlImageAttributes<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> htmlHelper.<span style="color: #0000FF;">ActionImage</span><span style="color: #000000;">&#40;</span>imageUrl, linkText, actionName, <span style="color: #0600FF;">null</span>, routeValues, htmlanchorAttributes, htmlImageAttributes<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">string</span> actionName, <span style="color: #FF0000;">string</span> controllerName, <span style="color: #FF0000;">object</span> routeValues, <span style="color: #FF0000;">object</span> htmlanchorAttributes<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> htmlHelper.<span style="color: #0000FF;">ActionImage</span><span style="color: #000000;">&#40;</span>imageUrl, linkText, actionName, controllerName, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span>routeValues<span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span>htmlanchorAttributes<span style="color: #000000;">&#41;</span>, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">string</span> actionName, <span style="color: #FF0000;">string</span> controllerName, <span style="color: #FF0000;">string</span> protocol, <span style="color: #FF0000;">string</span> hostName, <span style="color: #FF0000;">string</span> fragment, <span style="color: #FF0000;">object</span> routeValues, <span style="color: #FF0000;">object</span> htmlanchorAttributes, <span style="color: #FF0000;">object</span> htmlImageAttributes<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> htmlHelper.<span style="color: #0000FF;">ActionImage</span><span style="color: #000000;">&#40;</span>imageUrl, linkText, actionName, controllerName, protocol, hostName, fragment, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span>routeValues<span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span>htmlanchorAttributes<span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span>htmlImageAttributes<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #008000;">&lt;</span>TController<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, Expression<span style="color: #008000;">&lt;</span>Action<span style="color: #008000;">&lt;</span>TController<span style="color: #008000;">&gt;&gt;</span> action, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText<span style="color: #000000;">&#41;</span> where TController <span style="color: #008000;">:</span> Controller
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> htmlHelper.<span style="color: #0000FF;">ActionImage</span><span style="color: #000000;">&#40;</span>action, imageUrl, linkText, <span style="color: #0600FF;">null</span>, <span style="color: #0600FF;">null</span>, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #008000;">&lt;</span>TController<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, Expression<span style="color: #008000;">&lt;</span>Action<span style="color: #008000;">&lt;</span>TController<span style="color: #008000;">&gt;&gt;</span> action, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">object</span> routeValues<span style="color: #000000;">&#41;</span> where TController <span style="color: #008000;">:</span> Controller
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> htmlHelper.<span style="color: #0000FF;">ActionImage</span><span style="color: #000000;">&#40;</span>action, imageUrl, linkText, routeValues, <span style="color: #0600FF;">null</span>, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #008000;">&lt;</span>TController<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, Expression<span style="color: #008000;">&lt;</span>Action<span style="color: #008000;">&lt;</span>TController<span style="color: #008000;">&gt;&gt;</span> action, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">object</span> routeValues, <span style="color: #FF0000;">object</span> htmlanchorAttributes, <span style="color: #FF0000;">object</span> htmlImageAttributes<span style="color: #000000;">&#41;</span> where TController <span style="color: #008000;">:</span> Controller
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> htmlHelper.<span style="color: #0000FF;">ActionImage</span><span style="color: #000000;">&#40;</span>action, imageUrl, linkText, routeValues, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span>htmlanchorAttributes<span style="color: #000000;">&#41;</span>, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span>htmlImageAttributes<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #008000;">&lt;</span>TController<span style="color: #008000;">&gt;</span><span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, Expression<span style="color: #008000;">&lt;</span>Action<span style="color: #008000;">&lt;</span>TController<span style="color: #008000;">&gt;&gt;</span> action, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">object</span> routeValues, IDictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> htmlanchorAttributes, IDictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> htmlImageAttributes<span style="color: #000000;">&#41;</span> where TController <span style="color: #008000;">:</span> Controller
        <span style="color: #000000;">&#123;</span>
&nbsp;
            var _routeValuesFromExpression <span style="color: #008000;">=</span> ExpressionHelper.<span style="color: #0000FF;">GetRouteValuesFromExpression</span><span style="color: #000000;">&#40;</span>action<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            var _mergedRouteValues <span style="color: #008000;">=</span> MergeRouteValueDictionaries<span style="color: #000000;">&#40;</span>_routeValuesFromExpression, <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span>routeValues<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// get the action name</span>
            <span style="color: #008080; font-style: italic;">//</span>
            var _actionName <span style="color: #008000;">=</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>MethodCallExpression<span style="color: #000000;">&#41;</span>action.<span style="color: #0000FF;">Body</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Method</span>.<span style="color: #0000FF;">Name</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// get the bare url for the Action using the current</span>
            <span style="color: #008080; font-style: italic;">// request context</span>
            <span style="color: #008080; font-style: italic;">//     </span>
            var _url <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UrlHelper<span style="color: #000000;">&#40;</span>htmlHelper.<span style="color: #0000FF;">ViewContext</span>.<span style="color: #0000FF;">RequestContext</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Action</span><span style="color: #000000;">&#40;</span>_actionName, _mergedRouteValues<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> GetImageLink<span style="color: #000000;">&#40;</span>_url, linkText, imageUrl, htmlanchorAttributes, htmlImageAttributes<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">string</span> actionName, <span style="color: #FF0000;">string</span> controllerName, RouteValueDictionary routeValues, IDictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> htmlanchorAttributes, IDictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> htmlImageAttributes<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// get the bare url for the Action using the current</span>
            <span style="color: #008080; font-style: italic;">// request context</span>
            <span style="color: #008080; font-style: italic;">//</span>
            var _url <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UrlHelper<span style="color: #000000;">&#40;</span>htmlHelper.<span style="color: #0000FF;">ViewContext</span>.<span style="color: #0000FF;">RequestContext</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Action</span><span style="color: #000000;">&#40;</span>actionName, controllerName, routeValues<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> GetImageLink<span style="color: #000000;">&#40;</span>_url, linkText, imageUrl, htmlanchorAttributes, htmlImageAttributes<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> ActionImage<span style="color: #000000;">&#40;</span><span style="color: #0600FF;">this</span> HtmlHelper htmlHelper, <span style="color: #FF0000;">string</span> imageUrl, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">string</span> actionName, <span style="color: #FF0000;">string</span> controllerName, <span style="color: #FF0000;">string</span> protocol, <span style="color: #FF0000;">string</span> hostName, <span style="color: #FF0000;">string</span> fragment, RouteValueDictionary routeValues, IDictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> htmlanchorAttributes, IDictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> htmlImageAttributes<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// get the bare url for the Action using the current</span>
            <span style="color: #008080; font-style: italic;">// request context</span>
            <span style="color: #008080; font-style: italic;">//</span>
            var _url <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> UrlHelper<span style="color: #000000;">&#40;</span>htmlHelper.<span style="color: #0000FF;">ViewContext</span>.<span style="color: #0000FF;">RequestContext</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">Action</span><span style="color: #000000;">&#40;</span>actionName, controllerName, routeValues, protocol, hostName<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> GetImageLink<span style="color: #000000;">&#40;</span>_url, linkText, imageUrl, htmlanchorAttributes, htmlImageAttributes<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Build up the anchor and image tag.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;url&quot;&gt;The URL.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;linkText&quot;&gt;The link text.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;imageUrl&quot;&gt;The image URL.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;htmlanchorAttributes&quot;&gt;The HTML anchor attributes.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;htmlImageAttributes&quot;&gt;The HTML image attributes.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span style="color: #0600FF;">internal</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetImageLink<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> url, <span style="color: #FF0000;">string</span> linkText, <span style="color: #FF0000;">string</span> imageUrl, IDictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> htmlanchorAttributes, IDictionary<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> htmlImageAttributes<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// build up the image link.</span>
            <span style="color: #008080; font-style: italic;">// &lt;a href=\&quot;ActionUrl\&quot;&gt;&lt;img src=\&quot;ImageUrl\&quot; alt=\&quot;Your Link Text\&quot; /&gt;&lt;/a&gt;</span>
            <span style="color: #008080; font-style: italic;">//</span>
&nbsp;
            var _linkText <span style="color: #008000;">=</span> <span style="color: #008000;">!</span><span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">IsNullOrEmpty</span><span style="color: #000000;">&#40;</span>linkText<span style="color: #000000;">&#41;</span> <span style="color: #008000;">?</span> HttpUtility.<span style="color: #0000FF;">HtmlEncode</span><span style="color: #000000;">&#40;</span>linkText<span style="color: #000000;">&#41;</span> <span style="color: #008000;">:</span> <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Empty</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// build the img tag</span>
            <span style="color: #008080; font-style: italic;">//</span>
            TagBuilder _image <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TagBuilder<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;img&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            _image.<span style="color: #0000FF;">MergeAttributes</span><span style="color: #000000;">&#40;</span>htmlImageAttributes<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            _image.<span style="color: #0000FF;">MergeAttribute</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;src&quot;</span>, imageUrl<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            _image.<span style="color: #0000FF;">MergeAttribute</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;alt&quot;</span>, _linkText<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// build the anchor tag</span>
            <span style="color: #008080; font-style: italic;">//</span>
            TagBuilder _link <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> TagBuilder<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;a&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            _link.<span style="color: #0000FF;">MergeAttributes</span><span style="color: #000000;">&#40;</span>htmlanchorAttributes<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            _link.<span style="color: #0000FF;">MergeAttribute</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;href&quot;</span>, url<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// place the img tag inside the anchor tag.</span>
            <span style="color: #008080; font-style: italic;">//</span>
            _link.<span style="color: #0000FF;">InnerHtml</span> <span style="color: #008000;">=</span> _image.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span>TagRenderMode.<span style="color: #0000FF;">Normal</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// render the image link.</span>
            <span style="color: #008080; font-style: italic;">//</span>
            <span style="color: #0600FF;">return</span> _link.<span style="color: #0000FF;">ToString</span><span style="color: #000000;">&#40;</span>TagRenderMode.<span style="color: #0000FF;">Normal</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Merges the 2 source route value dictionaries.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;routeValueDictionary1&quot;&gt;RouteValueDictionary 1.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;routeValueDictionary2&quot;&gt;RouteValueDictionary 2.&lt;/param&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;returns&gt;&lt;/returns&gt;</span>
        <span style="color: #0600FF;">internal</span> <span style="color: #0600FF;">static</span> RouteValueDictionary MergeRouteValueDictionaries<span style="color: #000000;">&#40;</span>RouteValueDictionary routeValueDictionary1, RouteValueDictionary routeValueDictionary2<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var _mergedRouteValues <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> RouteValueDictionary<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span><span style="color: #000000;">&#40;</span>routeValueDictionary1 <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span> <span style="color: #008000;">&amp;</span> <span style="color: #000000;">&#40;</span>routeValueDictionary2 <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> routeElement <span style="color: #0600FF;">in</span> routeValueDictionary1<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    _mergedRouteValues<span style="color: #000000;">&#91;</span>routeElement.<span style="color: #0000FF;">Key</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> routeElement.<span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF;">foreach</span> <span style="color: #000000;">&#40;</span>KeyValuePair<span style="color: #008000;">&lt;</span><span style="color: #FF0000;">string</span>, <span style="color: #FF0000;">object</span><span style="color: #008000;">&gt;</span> routeElement <span style="color: #0600FF;">in</span> routeValueDictionary2<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    _mergedRouteValues<span style="color: #000000;">&#91;</span>routeElement.<span style="color: #0000FF;">Key</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> routeElement.<span style="color: #0000FF;">Value</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
&nbsp;
                <span style="color: #0600FF;">return</span> _mergedRouteValues<span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> null<span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://agilefutures.com/index.php/2009/06/actionimage-aspnet-mvc/feed/</wfw:commentRss>
		<slash:comments>9</slash:comments>
		</item>
		<item>
		<title>Kill all database connections</title>
		<link>http://agilefutures.com/index.php/2009/06/kill-all-database-connections/</link>
		<comments>http://agilefutures.com/index.php/2009/06/kill-all-database-connections/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 18:46:28 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Kill Connections]]></category>

		<guid isPermaLink="false">http://agilefutures.com/?p=124</guid>
		<description><![CDATA[Just came across this script – very useful 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 -------------------------------------------------------------------------------------- /*** CREATED BY AJITH DHARWAR ***/ /*** This [...]]]></description>
			<content:encoded><![CDATA[<p>Just came across this script – very useful</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
</pre></td><td class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #008080;">--------------------------------------------------------------------------------------</span>
<span style="color: #008080;">/*** CREATED BY AJITH DHARWAR                                                     ***/</span>
<span style="color: #008080;">/*** This procedure will accept a DB name and drop all connections to the DB.    ***/</span>
<span style="color: #008080;">--------------------------------------------------------------------------------------</span>
<span style="color: #0000FF;">CREATE</span> <span style="color: #0000FF;">PROCEDURE</span> usp_killDBConnections
    @DBName <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">50</span><span style="color: #808080;">&#41;</span>,
    @withmsg <span style="color: #0000FF;">BIT</span> <span style="color: #808080;">=</span> <span style="color: #000;">1</span>
<span style="color: #0000FF;">AS</span> 
    <span style="color: #0000FF;">SET</span> <span style="color: #0000FF;">NOCOUNT</span> <span style="color: #0000FF;">ON</span>
    <span style="color: #0000FF;">DECLARE</span> @spidstr <span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">8000</span><span style="color: #808080;">&#41;</span>
    <span style="color: #0000FF;">DECLARE</span> @ConnKilled <span style="color: #0000FF;">SMALLINT</span>
    <span style="color: #0000FF;">SET</span> @ConnKilled <span style="color: #808080;">=</span> <span style="color: #000;">0</span>
    <span style="color: #0000FF;">SET</span> @spidstr <span style="color: #808080;">=</span> <span style="color: #FF0000;">''</span>
&nbsp;
    <span style="color: #0000FF;">IF</span> <span style="color: #FF00FF;">DB_ID</span><span style="color: #808080;">&#40;</span>@DBName<span style="color: #808080;">&#41;</span> <span style="color: #808080;">&gt;</span> <span style="color: #000;">4</span> 
        <span style="color: #0000FF;">BEGIN</span>
            <span style="color: #0000FF;">PRINT</span> <span style="color: #FF0000;">'Connections to system databases cannot be killed'</span>
            <span style="color: #0000FF;">RETURN</span>
        <span style="color: #0000FF;">END</span>
&nbsp;
    <span style="color: #0000FF;">SELECT</span>  @spidstr <span style="color: #808080;">=</span> <span style="color: #0000FF;">COALESCE</span><span style="color: #808080;">&#40;</span>@spidstr, <span style="color: #FF0000;">','</span><span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'kill '</span> <span style="color: #808080;">+</span> <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">VARCHAR</span>, spid<span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">'; '</span>
    <span style="color: #0000FF;">FROM</span>    master..<span style="color: #202020;">sysprocesses</span>
    <span style="color: #0000FF;">WHERE</span>   dbid <span style="color: #808080;">=</span> <span style="color: #FF00FF;">DB_ID</span><span style="color: #808080;">&#40;</span>@DBName<span style="color: #808080;">&#41;</span>
&nbsp;
    <span style="color: #0000FF;">IF</span> <span style="color: #FF00FF;">LEN</span><span style="color: #808080;">&#40;</span>@spidstr<span style="color: #808080;">&#41;</span> <span style="color: #808080;">&amp;</span>gt; <span style="color: #000;">0</span> 
        <span style="color: #0000FF;">BEGIN</span>
            <span style="color: #0000FF;">EXEC</span> <span style="color: #808080;">&#40;</span> @spidstr
                <span style="color: #808080;">&#41;</span>
&nbsp;
            <span style="color: #0000FF;">SELECT</span>  @ConnKilled <span style="color: #808080;">=</span> <span style="color: #FF00FF;">COUNT</span><span style="color: #808080;">&#40;</span><span style="color: #000;">1</span><span style="color: #808080;">&#41;</span>
            <span style="color: #0000FF;">FROM</span>    master..<span style="color: #202020;">sysprocesses</span>
            <span style="color: #0000FF;">WHERE</span>   dbid <span style="color: #808080;">=</span> <span style="color: #FF00FF;">DB_ID</span><span style="color: #808080;">&#40;</span>@DBName<span style="color: #808080;">&#41;</span> 
&nbsp;
        <span style="color: #0000FF;">END</span>
&nbsp;
    <span style="color: #0000FF;">IF</span> @withmsg <span style="color: #808080;">=</span> <span style="color: #000;">1</span> 
        <span style="color: #0000FF;">PRINT</span> <span style="color: #0000FF;">CONVERT</span><span style="color: #808080;">&#40;</span><span style="color: #0000FF;">VARCHAR</span><span style="color: #808080;">&#40;</span><span style="color: #000;">10</span><span style="color: #808080;">&#41;</span>, @ConnKilled<span style="color: #808080;">&#41;</span> <span style="color: #808080;">+</span> <span style="color: #FF0000;">' Connection(s) killed for DB '</span> <span style="color: #808080;">+</span> @DBName
GO</pre></td></tr></table></div>

</p>
<p>You can then use it like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">EXEC</span> sp_msforeachdb <span style="color: #FF0000;">'EXEC usp_killDBConnections @DBName='</span><span style="color: #FF0000;">'?'</span><span style="color: #FF0000;">''</span></pre></td></tr></table></div>

</p>
<p>Or like this</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
</pre></td><td class="code"><pre class="tsql" style="font-family:monospace;"><span style="color: #0000FF;">EXEC</span> usp_killDBConnections @DBName<span style="color: #808080;">=</span><span style="color: #FF0000;">'MyDatabase'</span></pre></td></tr></table></div>

]]></content:encoded>
			<wfw:commentRss>http://agilefutures.com/index.php/2009/06/kill-all-database-connections/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Report Server &amp; ASP.MVC</title>
		<link>http://agilefutures.com/index.php/2009/06/sql-report-server-aspmvc/</link>
		<comments>http://agilefutures.com/index.php/2009/06/sql-report-server-aspmvc/#comments</comments>
		<pubDate>Sun, 07 Jun 2009 08:46:53 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[SSRS]]></category>
		<category><![CDATA[ReportServerResult]]></category>

		<guid isPermaLink="false">http://agilefutures.com/?p=105</guid>
		<description><![CDATA[I have used MS SQL Report server a lot and one of the most common scenarios is to render a report and have it download a PDF / Excel etc. I have not seen many posts regarding how to do this end-to-end using MVC. So I thought I share my method. The demo project will [...]]]></description>
			<content:encoded><![CDATA[<p>I have used MS SQL Report server a lot and one of the most common scenarios is to render a report and have it download a PDF / Excel etc. I have not seen many posts regarding how to do this end-to-end using MVC. So I thought I share my method.</p>
<p>The demo project will be split into 3 parts.</p>
<ol>
<li>The Report Server Execution Service.<br />
2. The Report Server Repository Layer.<br />
3. The Report Server Service Layer.<br />
4. The User Interface.<br />
You’ll need</li>
</ol>
<ol>
<li><a href="http://www.microsoft.com/Express/ " target="_blank">Visual Studio 2008</a></li>
<li><a href="http://www.asp.net/mvc/" target="_blank">ASP.MVC RTM</a></li>
<li><a href="http://msdn.microsoft.com/en-us/sqlserver/default.aspx" target="_blank">SQL Server 2005/2008</a></li>
</ol>
<p>You’ll also have installed and working the MSSQL Report Server and a test report.Create a New Blank Solution SQL Server Report Solution</p>
<p><a href="http://agilefutures.com/wp-content/uploads/2009/06/image1.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://agilefutures.com/wp-content/uploads/2009/06/image-thumb1.png" border="0" alt="image" width="244" height="122" /></a>And then add 2 Class Libraries and a MVC Web Site – You can choose whether or not to add the MVC Test projects.</p>
<ul>
<li>Demos.SqlReports.Data</li>
<li>Demos.SqlReports.Services</li>
<li>Demos.SqlReports.Web</li>
</ul>
<p>I’ll also add a test project for the Data and Service Layer, I’m just using the default unit test framework that comes with VS 2008. You can of course use something else (nUnit, xUnit etc).</p>
<ul>
<li>Demos.SqlReports.Tests</li>
</ul>
<ul>You should have something like this now.</ul>
<p><a href="http://agilefutures.com/wp-content/uploads/2009/06/image2.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://agilefutures.com/wp-content/uploads/2009/06/image-thumb2.png" border="0" alt="image" width="329" height="192" /></a> </p>
<p>We need to add a Web Reference to the Report Server at the data layer. My Report Server Execution Service URL is</p>
<p><strong>http://localhost/ReportServer$SQLSERVER_001/ReportExecution2005.asmx</strong></p>
<p>Yours may differ so check it in IIS.</p>
<p>Also, I’m adding a web reference – not a service reference. You can do this though the add service reference dialog box by clicking Advanced | Add Web Reference.</p>
<p><a href="http://agilefutures.com/wp-content/uploads/2009/06/image3.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://agilefutures.com/wp-content/uploads/2009/06/image-thumb3.png" border="0" alt="image" width="430" height="299" /></a></p>
<p>I always postfix Proxy on the end of the Web Reference Name for clarity.</p>
<p>Once added rename Class 1  to ReportServerRepository.cs and also create an Interface Class IReportsRepository.cs</p>
<p>Move these files into a sub folder Data so they are organised.</p>
<p><a href="http://agilefutures.com/wp-content/uploads/2009/06/image4.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" src="http://agilefutures.com/wp-content/uploads/2009/06/image-thumb4.png" border="0" alt="image" width="244" height="155" /></a></p>
<p>Let’s add some code.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.IO</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Net</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text.RegularExpressions</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Services.Protocols</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Demos.SqlReports.Data.ReportExecution2005Proxy</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Demos.<span style="color: #0000FF;">SqlReports</span>.<span style="color: #0000FF;">Data</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #008080; font-style: italic;">/// Contains the response data from a RenderReport request</span>
    <span style="color: #008080; font-style: italic;">/// to the report server.</span>
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">sealed</span> <span style="color: #FF0000;">class</span> RenderReportResponse
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">byte</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> ReportData <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> ExecutionInfo ExecutionInfo <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> ReportExecution2005Proxy.<span style="color: #0000FF;">Warning</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> Warnings <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> SessionId <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> ContentType <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> HistoryID <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> DevInfo <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Encoding <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> MimeType <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> Extension <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> StreamIds <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #008080; font-style: italic;">/// Report Server Repository</span>
    <span style="color: #008080; font-style: italic;">///</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">sealed</span> <span style="color: #FF0000;">class</span> ReportServerRepository <span style="color: #008000;">:</span> IReportsRepository
    <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #008080;">#region Constructors</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">/// Initializes a new instance of the  class.</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #0600FF;">public</span> ReportServerRepository<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">this</span>.<span style="color: #0000FF;">Initialise</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region Declarations</span>
&nbsp;
        <span style="color: #0600FF;">private</span> NetworkCredential netCredential<span style="color: #008000;">;</span>
        <span style="color: #0600FF;">private</span> ReportExecutionService webServiceProxy<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region Private Members</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">/// Initialises this instance and set the credentials for</span>
        <span style="color: #008080; font-style: italic;">/// the report server.</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">void</span> Initialise<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            webServiceProxy <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ReportExecutionService<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            netCredential <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> NetworkCredential<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;MyUserName&quot;</span>, <span style="color: #666666;">&quot;MyPassword&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            Uri uri <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> Uri<span style="color: #000000;">&#40;</span>webServiceProxy.<span style="color: #0000FF;">Url</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            ICredentials credentials <span style="color: #008000;">=</span> netCredential.<span style="color: #0000FF;">GetCredential</span><span style="color: #000000;">&#40;</span>uri, <span style="color: #666666;">&quot;Basic&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            webServiceProxy.<span style="color: #0000FF;">Credentials</span> <span style="color: #008000;">=</span> credentials<span style="color: #008000;">;</span>
            webServiceProxy.<span style="color: #0000FF;">PreAuthenticate</span> <span style="color: #008000;">=</span> true<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">/// Gets the type of the content.</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">///</span>
The file extension.
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> <span style="color: #FF0000;">string</span> GetContentType<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> fileExtension<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">switch</span> <span style="color: #000000;">&#40;</span>fileExtension.<span style="color: #0000FF;">ToLower</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #0600FF;">case</span> <span style="color: #666666;">&quot;.pdf&quot;</span><span style="color: #008000;">:</span> <span style="color: #0600FF;">return</span> <span style="color: #666666;">&quot;application/pdf&quot;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> <span style="color: #666666;">&quot;.tif&quot;</span><span style="color: #008000;">:</span> <span style="color: #0600FF;">return</span> <span style="color: #666666;">&quot;image/tiff&quot;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> <span style="color: #666666;">&quot;.xls&quot;</span><span style="color: #008000;">:</span> <span style="color: #0600FF;">return</span> <span style="color: #666666;">&quot;application/ms-excel&quot;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">case</span> <span style="color: #666666;">&quot;.xml&quot;</span><span style="color: #008000;">:</span> <span style="color: #0600FF;">return</span> <span style="color: #666666;">&quot;text/xml&quot;</span><span style="color: #008000;">;</span>
                <span style="color: #0600FF;">default</span><span style="color: #008000;">:</span> <span style="color: #0600FF;">return</span> <span style="color: #666666;">&quot;text/plain&quot;</span><span style="color: #008000;">;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">/// Renders the report.</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">///</span>
The parameters.
        <span style="color: #008080; font-style: italic;">///</span>
The report path.
        <span style="color: #008080; font-style: italic;">///</span>
The format.
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">static</span> RenderReportResponse RenderReport<span style="color: #000000;">&#40;</span>ReportExecution2005Proxy.<span style="color: #0000FF;">ParameterValue</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> parameters, <span style="color: #FF0000;">string</span> reportPath, <span style="color: #FF0000;">string</span> format<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            <span style="color: #0600FF;">using</span> <span style="color: #000000;">&#40;</span>var rs <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ReportExecutionService<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
&nbsp;
                <span style="color: #0600FF;">try</span>
                <span style="color: #000000;">&#123;</span>
&nbsp;
                    rs.<span style="color: #0000FF;">Credentials</span> <span style="color: #008000;">=</span> CredentialCache.<span style="color: #0000FF;">DefaultCredentials</span><span style="color: #008000;">;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;">// Render arguments</span>
                    <span style="color: #008080; font-style: italic;">//</span>
                    <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> _historyID <span style="color: #008000;">=</span> null<span style="color: #008000;">;</span>
                    <span style="color: #0600FF;">const</span> <span style="color: #FF0000;">string</span> _devInfo <span style="color: #008000;">=</span> <span style="color: #666666;">@&quot;False&quot;</span><span style="color: #008000;">;</span>
                    <span style="color: #FF0000;">string</span> _encoding<span style="color: #008000;">;</span>
                    <span style="color: #FF0000;">string</span> _mimeType<span style="color: #008000;">;</span>
                    <span style="color: #FF0000;">string</span> _extension<span style="color: #008000;">;</span>
                    ReportExecution2005Proxy.<span style="color: #0000FF;">Warning</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> _warnings<span style="color: #008000;">;</span>
                    <span style="color: #FF0000;">string</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> _streamIDs<span style="color: #008000;">;</span>
&nbsp;
                    ExecutionInfo _execInfo <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ExecutionInfo<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    ExecutionHeader execHeader <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ExecutionHeader<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                    rs.<span style="color: #0000FF;">ExecutionHeaderValue</span> <span style="color: #008000;">=</span> execHeader<span style="color: #008000;">;</span>
                    _execInfo <span style="color: #008000;">=</span> rs.<span style="color: #0000FF;">LoadReport</span><span style="color: #000000;">&#40;</span>reportPath, _historyID<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                    rs.<span style="color: #0000FF;">SetExecutionParameters</span><span style="color: #000000;">&#40;</span>parameters, <span style="color: #666666;">&quot;en-us&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                    <span style="color: #FF0000;">String</span> SessionId <span style="color: #008000;">=</span> rs.<span style="color: #0000FF;">ExecutionHeaderValue</span>.<span style="color: #0000FF;">ExecutionID</span><span style="color: #008000;">;</span>
&nbsp;
                    var _reportData <span style="color: #008000;">=</span> rs.<span style="color: #0000FF;">Render</span><span style="color: #000000;">&#40;</span>format, _devInfo, <span style="color: #0600FF;">out</span> _extension, <span style="color: #0600FF;">out</span> _encoding, <span style="color: #0600FF;">out</span> _mimeType, <span style="color: #0600FF;">out</span> _warnings, <span style="color: #0600FF;">out</span> _streamIDs<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                    var _response <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> RenderReportResponse
                                        <span style="color: #000000;">&#123;</span>
                                            ReportData <span style="color: #008000;">=</span> _reportData,
                                            ExecutionInfo <span style="color: #008000;">=</span> _execInfo,
                                            Warnings <span style="color: #008000;">=</span> _warnings,
                                            SessionId <span style="color: #008000;">=</span> SessionId,
                                            ContentType <span style="color: #008000;">=</span> GetContentType<span style="color: #000000;">&#40;</span>format<span style="color: #000000;">&#41;</span>,
                                            HistoryID <span style="color: #008000;">=</span> _historyID,
                                            DevInfo <span style="color: #008000;">=</span> _devInfo,
                                            Encoding <span style="color: #008000;">=</span> _encoding,
                                            MimeType <span style="color: #008000;">=</span> _mimeType,
                                            Extension <span style="color: #008000;">=</span> _extension,
                                            StreamIds <span style="color: #008000;">=</span> _streamIDs
                                        <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
                    <span style="color: #0600FF;">return</span> _response<span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #000000;">&#125;</span>
                <span style="color: #0600FF;">catch</span> <span style="color: #000000;">&#40;</span>SoapException e<span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
&nbsp;
                    <span style="color: #008080; font-style: italic;">// handle exception</span>
                    <span style="color: #008080; font-style: italic;">//</span>
                    <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> ApplicationException<span style="color: #000000;">&#40;</span>
                        <span style="color: #FF0000;">string</span>.<span style="color: #0000FF;">Format</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Error occurred rendering the report : {0}&quot;</span>, reportPath<span style="color: #000000;">&#41;</span>, e<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
&nbsp;
        <span style="color: #008080;">#region IReportServerRepository Members</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">/// Renders the Demo Report.</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">///</span>
The reportParameter.
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #0600FF;">public</span> RenderReportResponse RenderDemoReport<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> reportParameter<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            var _params <span style="color: #008000;">=</span> <span style="color: #008000;">new</span><span style="color: #000000;">&#91;</span><span style="color: #000000;">&#93;</span> <span style="color: #000000;">&#123;</span> <span style="color: #008000;">new</span> ReportExecution2005Proxy.<span style="color: #0000FF;">ParameterValue</span> <span style="color: #000000;">&#123;</span> Name <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;p_ReportParameter&quot;</span>, Value <span style="color: #008000;">=</span> reportParameter <span style="color: #000000;">&#125;</span> <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> RenderReport<span style="color: #000000;">&#40;</span>_params, <span style="color: #666666;">&quot;My Demo Report&quot;</span>, <span style="color: #666666;">&quot;PDF&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>And add some to the interface class</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Demos.<span style="color: #0000FF;">SqlReports</span>.<span style="color: #0000FF;">Data</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #FF0000;">interface</span> IReportsRepository
    <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">/// Renders the Demo Report.</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">///</span>
The reportParameter.
        <span style="color: #008080; font-style: italic;">///</span>
        RenderReportResponse RenderDemoReport<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> reportParameter<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The reason for returning a class of <strong>RenderReportResponse</strong> back is that we can have the whole response delivered to the UI and make use of it if required.</p>
<p>Ok let’s add some code to the service class.</p>
<p>Rename Class 1  to <strong>ReportService.cs</strong> and also create an Interface Class <strong>IReportService.cs </strong></p>
<p>The purpose of the interfaces and the service class is to abstract away the implementation of the repository and to decouple as much as possible.</p>
<p>The UI should only ever call the service class. You can then swap out repositories easily when testing code or using an alternative repository. It also lends its self well to a plug-in architecture or if you plan to implement IoC / Dependency Injection later on.</p>
<p>Code for the Service Class</p>
<p>(make sure you have added a project reference for <strong>Demos.SqlReports.Data)</strong></p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Demos.SqlReports.Data</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Demos.<span style="color: #0000FF;">SqlReports</span>.<span style="color: #0000FF;">Services</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">partial</span> <span style="color: #FF0000;">class</span> ReportService <span style="color: #008000;">:</span> IReportService
    <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #0600FF;">readonly</span> IReportsRepository _repository<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">/// Creates a ReportService based on the passed-in repository</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">///</span>
An IReportsRepository
        <span style="color: #0600FF;">public</span> ReportService<span style="color: #000000;">&#40;</span>IReportsRepository repository<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            _repository <span style="color: #008000;">=</span> repository<span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_repository <span style="color: #008000;">==</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
                <span style="color: #0600FF;">throw</span> <span style="color: #008000;">new</span> InvalidOperationException<span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;Repository cannot be null&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">/// Creates a ReportService based on the default repository</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #0600FF;">public</span> ReportService<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            _repository <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ReportServerRepository<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#region IReportService Members</span>
&nbsp;
        <span style="color: #0600FF;">public</span> RenderReportResponse RenderDemoReport<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> reportParameter<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> _repository.<span style="color: #0000FF;">RenderDemoReport</span><span style="color: #000000;">&#40;</span>reportParameter<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080;">#endregion</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p> </p>
<p>Code for the Service Interface Class</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Text</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Demos.SqlReports.Data</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Demos.<span style="color: #0000FF;">SqlReports</span>.<span style="color: #0000FF;">Services</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">interface</span> IReportService
    <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">/// Renders the Demo Report.</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">///</span>
The reportParameter.
        <span style="color: #008080; font-style: italic;">///</span>
        RenderReportResponse RenderDemoReport<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> reportParameter<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
&nbsp;
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p> </p>
<p>Move these files into a sub directory i.e. Reports. Build the project make sure there are no errors.</p>
<p> </p>
<h3>Implementing the UI</h3>
<p> </p>
<p>In the MVC Project we are going to use the default <strong>HomeController</strong> for our demo. Add a project reference for the Data and Service Layers.</p>
<p>The first thing we need to do is create a class for the ActionResultHelper.cs. Add the class file in a subdirectory Helpers (keep the class namespace flat i.e. <strong>Demos.SqlReports.Web </strong>remove any namespace additions if you create the sub directory first.</p>
<p>Add the code.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Demos.SqlReports.Services</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Demos.SqlReports.Data</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Demos.<span style="color: #0000FF;">SqlReports</span>.<span style="color: #0000FF;">Web</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> ReportServerResult <span style="color: #008000;">:</span> ActionResult
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> RenderReportResponse ReportData <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> FileName <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> ExecuteResult<span style="color: #000000;">&#40;</span>ControllerContext context<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
&nbsp;
            context.<span style="color: #0000FF;">HttpContext</span>.<span style="color: #0000FF;">Response</span>.<span style="color: #0000FF;">Clear</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            context.<span style="color: #0000FF;">HttpContext</span>.<span style="color: #0000FF;">Response</span>.<span style="color: #0000FF;">ClearHeaders</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            context.<span style="color: #0000FF;">HttpContext</span>.<span style="color: #0000FF;">Response</span>.<span style="color: #0000FF;">ContentType</span> <span style="color: #008000;">=</span> ReportData.<span style="color: #0000FF;">ContentType</span><span style="color: #008000;">;</span>
            context.<span style="color: #0000FF;">HttpContext</span>.<span style="color: #0000FF;">Response</span>.<span style="color: #0000FF;">AddHeader</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;content-disposition&quot;</span>, <span style="color: #666666;">&quot;attachment; filename=&quot;</span><span style="color: #666666;">&quot; + FileName + &quot;</span><span style="color: #666666;">&quot;&quot;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            context.<span style="color: #0000FF;">HttpContext</span>.<span style="color: #0000FF;">Response</span>.<span style="color: #0000FF;">BinaryWrite</span><span style="color: #000000;">&#40;</span>ReportData.<span style="color: #0000FF;">ReportData</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
            context.<span style="color: #0000FF;">HttpContext</span>.<span style="color: #0000FF;">Response</span>.<span style="color: #0000FF;">Flush</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>Let me explain a little what&#8217;s going on here. By inheriting the <strong>ActionResult</strong> base class we can pass the report servers response directly to the response stream of the Controller Action. This is a neat way because it also allows you to Unit Test the response and you can reuse it anywhere you render a report.</p>
<p>Let’s create an Action in Home Controller.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Demos.SqlReports.Services</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">Demos.SqlReports.Data</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> Demos.<span style="color: #0000FF;">SqlReports</span>.<span style="color: #0000FF;">Web</span>.<span style="color: #0000FF;">Controllers</span>
<span style="color: #000000;">&#123;</span>
    <span style="color: #000000;">&#91;</span>HandleError<span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> HomeController <span style="color: #008000;">:</span> Controller
    <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #0600FF;">private</span> <span style="color: #0600FF;">readonly</span> IReportService _reportService<span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> HomeController<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            _reportService <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> ReportService<span style="color: #000000;">&#40;</span><span style="color: #008000;">new</span> ReportServerRepository<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> ActionResult Index<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            ViewData<span style="color: #000000;">&#91;</span><span style="color: #666666;">&quot;Message&quot;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Welcome to ASP.NET MVC!&quot;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> View<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> ActionResult About<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #0600FF;">return</span> View<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">/// Gets the demo report.</span>
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #008080; font-style: italic;">///</span>
The report parameter.
        <span style="color: #008080; font-style: italic;">///</span>
        <span style="color: #0600FF;">public</span> ActionResult GetDemoReport<span style="color: #000000;">&#40;</span><span style="color: #FF0000;">string</span> reportparameter<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// call the report service and render the report</span>
            <span style="color: #008080; font-style: italic;">//</span>
&nbsp;
            var _response <span style="color: #008000;">=</span> _reportService.<span style="color: #0000FF;">RenderDemoReport</span><span style="color: #000000;">&#40;</span>reportparameter<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #008080; font-style: italic;">// returnn the result using a custom action result class.</span>
            <span style="color: #008080; font-style: italic;">//</span>
            <span style="color: #0600FF;">return</span> <span style="color: #008000;">new</span> ReportServerResult <span style="color: #000000;">&#123;</span> FileName <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Demo Report.pdf&quot;</span>, ReportData <span style="color: #008000;">=</span> _response <span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>As you can see the code is nice and concise. The Response Data from service layer is passed straight into the ReportServerResult  which outputs the report to the response stream.</p>
<p>Add an ActionLink to the Index.aspx file</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
</pre></td><td class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #006600; font-weight: bold;">&amp;</span>lt<span style="color: #006600; font-weight: bold;">;</span> <span style="color: #006600; font-weight: bold;">%@</span> Page Language<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;C#&quot;</span> MasterPageFile<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;~/Views/Shared/Site.Master&quot;</span> Inherits<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;System.Web.Mvc.ViewPage&quot;</span> <span style="color: #006600; font-weight: bold;">%&amp;</span>gt<span style="color: #006600; font-weight: bold;">;</span>
&nbsp;
    Home Page
<span style="color: #006600; font-weight: bold;">&lt;</span>h2<span style="color: #006600; font-weight: bold;">&gt;</span>
        <span style="color: #006600; font-weight: bold;">&amp;</span>lt<span style="color: #006600; font-weight: bold;">;</span> <span style="color: #006600; font-weight: bold;">%=</span> Html.<span style="color: #9900cc;">Encode</span><span style="color: #006600; font-weight:bold;">&#40;</span>ViewData<span style="color: #006600; font-weight:bold;">&#91;</span><span style="color: #cc0000;">&quot;Message&quot;</span><span style="color: #006600; font-weight:bold;">&#93;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">%&amp;</span>gt<span style="color: #006600; font-weight: bold;">;&lt;/</span>h2<span style="color: #006600; font-weight: bold;">&gt;</span>
<span style="color: #990099; font-weight: bold;">To</span> learn more about ASP.<span style="color: #9900cc;">NET</span> MVC visit <span style="color: #006600; font-weight: bold;">&lt;</span>a title<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;ASP.NET MVC Website&quot;</span> href<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;http://asp.net/mvc&quot;</span><span style="color: #006600; font-weight: bold;">&gt;</span>
            http<span style="color: #006600; font-weight: bold;">:</span><span style="color: #ff6600;">//asp.net/mvc&lt;/a&gt;.</span>
&nbsp;
        <span style="color: #006600; font-weight: bold;">&amp;</span>lt<span style="color: #006600; font-weight: bold;">;</span> <span style="color: #006600; font-weight: bold;">%=</span> Html.<span style="color: #9900cc;">ActionLink</span><span style="color: #006600; font-weight:bold;">&#40;</span><span style="color: #cc0000;">&quot;Render Report&quot;</span>,<span style="color: #cc0000;">&quot;GetDemoReport&quot;</span>, <span style="color: #cc0000;">&quot;HomeController&quot;</span>,<span style="color: #0000ff; font-weight: bold;">new</span><span style="color: #006600; font-weight:bold;">&#123;</span> reportparameter <span style="color: #006600; font-weight: bold;">=</span> <span style="color: #cc0000;">&quot;ParameterValue&quot;</span><span style="color: #006600; font-weight:bold;">&#125;</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #006600; font-weight: bold;">%&amp;</span>gt<span style="color: #006600; font-weight: bold;">;</span></pre></td></tr></table></div>

<p> </p>
<p>That’s it. normally I’d build the unit tests before jumping into the code but this isn’t a session on TDD. I’ll leave that bit to you. Next I’d like to get the Report Viewer control working with ASP.MVC. You can download the test solution here.</p>
<div id="scid:18d43e01-4549-4fde-8ca6-c7b4b7385fac:57e8aef4-dd07-4526-bee5-e1597338db56" class="wlWriterEditableSmartContent" style="padding-bottom: 0px; margin: 0px; padding-left: 0px; padding-right: 0px; display: inline; float: none; padding-top: 0px">
<p>Download Solution &#8211; <a href="http://agilefutures.com/wp-content/uploads/2009/06/sqlserverreportsolution5.zip">SQL Server Report Solution.zip</a></div>
]]></content:encoded>
			<wfw:commentRss>http://agilefutures.com/index.php/2009/06/sql-report-server-aspmvc/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>MVC – Strongly Typed Global ViewData</title>
		<link>http://agilefutures.com/index.php/2009/06/mvc-strongly-typed-global-viewdata/</link>
		<comments>http://agilefutures.com/index.php/2009/06/mvc-strongly-typed-global-viewdata/#comments</comments>
		<pubDate>Tue, 02 Jun 2009 12:25:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[ASP.NET MVC]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Strongly Typed]]></category>
		<category><![CDATA[ViewData]]></category>

		<guid isPermaLink="false">http://agilefutures.com/?p=66</guid>
		<description><![CDATA[Most MVC stuff I have been doing has been quite basic and the knowledge gleaned off many blog sites ( thanks to you all )I’m not a prolific blogger – too busy!!!, I’ll only blog when I have something to useful to share that isn’t easy to find. I was looking for a way to [...]]]></description>
			<content:encoded><![CDATA[<p>Most MVC stuff I have been doing has been quite basic and the knowledge gleaned off many blog sites ( thanks to you all <img src='http://agilefutures.com/wp-includes/images/smilies/icon_smile.gif' alt=':-)' class='wp-smiley' />  )I’m not a prolific blogger – too busy!!!, I’ll only blog when I have something to useful to share that isn’t easy to find.    </p>
<p> I was looking for a way to provide ViewData at the Model level so that I could have some parameters available after every action that were strongly typed and injected into the ActionResult instead of ViewData[&quot;MyData&quot;]. I want to use Model.MyData</p>
<p>I had a good search about but nothing definitive so I cam up with this.    </p>
<p> The Base Controller Class.     </p>
<p> It’s always a good idea to have you own base controller that is inherited from your other controllers. Here we are using it for storing Global Settings/Properties or any helper methods etc.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> GlobalViewData.<span style="color: #0000FF;">Controllers</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Base data container for ViewData Models</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF;">public</span> abstract <span style="color: #FF0000;">class</span> BaseFormViewModel
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> MyData <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
    <span style="color: #008080; font-style: italic;">/// Base controller that all controllers inherit from.</span>
    <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
    <span style="color: #0600FF;">public</span> abstract <span style="color: #FF0000;">class</span> BaseController <span style="color: #008000;">:</span> Controller
    <span style="color: #000000;">&#123;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Initializes a new instance of the &lt;see cref=&quot;BaseController&quot; /&gt; class.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #0600FF;">protected</span> BaseController<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            MyData <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;I have set this in the BaseController&quot;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> MyData <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #008080; font-style: italic;">/// &lt;summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// Method called after the action method is invoked.</span>
        <span style="color: #008080; font-style: italic;">/// &lt;/summary&gt;</span>
        <span style="color: #008080; font-style: italic;">/// &lt;param name=&quot;filterContext&quot; /&gt;Contains information about the current request and action.</span>
        <span style="color: #0600FF;">protected</span> <span style="color: #0600FF;">override</span> <span style="color: #0600FF;">void</span> OnActionExecuted<span style="color: #000000;">&#40;</span>ActionExecutedContext filterContext<span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            <span style="color: #008080; font-style: italic;">// check there is data in the Model</span>
            <span style="color: #008080; font-style: italic;">//</span>
            <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>filterContext.<span style="color: #0000FF;">Controller</span>.<span style="color: #0000FF;">ViewData</span>.<span style="color: #0000FF;">Model</span> <span style="color: #008000;">!=</span> <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span>
            <span style="color: #000000;">&#123;</span>
                <span style="color: #008080; font-style: italic;">// bit of reflection magic and get the types</span>
                <span style="color: #008080; font-style: italic;">//</span>
                Type _baseFormViewModelType <span style="color: #008000;">=</span> <span style="color: #008000;">typeof</span><span style="color: #000000;">&#40;</span>BaseFormViewModel<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                Type _modelType <span style="color: #008000;">=</span> filterContext.<span style="color: #0000FF;">Controller</span>.<span style="color: #0000FF;">ViewData</span>.<span style="color: #0000FF;">Model</span>.<span style="color: #0000FF;">GetType</span><span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
                <span style="color: #008080; font-style: italic;">// if the model type is derived from the base type then</span>
                <span style="color: #008080; font-style: italic;">// we can set some properties.</span>
                <span style="color: #008080; font-style: italic;">//</span>
&nbsp;
                <span style="color: #0600FF;">if</span> <span style="color: #000000;">&#40;</span>_baseFormViewModelType.<span style="color: #0000FF;">IsAssignableFrom</span><span style="color: #000000;">&#40;</span>_modelType<span style="color: #000000;">&#41;</span><span style="color: #000000;">&#41;</span>
                <span style="color: #000000;">&#123;</span>
                    <span style="color: #008080; font-style: italic;">// inject the value to the ViewData.Model property</span>
                    <span style="color: #008080; font-style: italic;">//</span>
                    _modelType.<span style="color: #0000FF;">GetProperty</span><span style="color: #000000;">&#40;</span><span style="color: #666666;">&quot;MyData&quot;</span><span style="color: #000000;">&#41;</span>.<span style="color: #0000FF;">SetValue</span><span style="color: #000000;">&#40;</span>filterContext.<span style="color: #0000FF;">Controller</span>.<span style="color: #0000FF;">ViewData</span>.<span style="color: #0000FF;">Model</span>, MyData, <span style="color: #0600FF;">null</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
                <span style="color: #000000;">&#125;</span>
            <span style="color: #000000;">&#125;</span>
&nbsp;
            <span style="color: #0600FF;">base</span>.<span style="color: #0000FF;">OnActionExecuted</span><span style="color: #000000;">&#40;</span>filterContext<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
&nbsp;
        <span style="color: #000000;">&#125;</span>       
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>The Home Controller Class</p>
<p>This inherits from the BaseController and also has a Data Class called HomeFormViewModel which inherits from BaseFormViewModel.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
</pre></td><td class="code"><pre class="csharp" style="font-family:monospace;"><span style="color: #0600FF;">using</span> <span style="color: #008080;">System</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Collections.Generic</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Linq</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web</span><span style="color: #008000;">;</span>
<span style="color: #0600FF;">using</span> <span style="color: #008080;">System.Web.Mvc</span><span style="color: #008000;">;</span>
&nbsp;
<span style="color: #0600FF;">namespace</span> GlobalViewData.<span style="color: #0000FF;">Controllers</span>
<span style="color: #000000;">&#123;</span>
&nbsp;
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> HomeFormViewModel <span style="color: #008000;">:</span> BaseFormViewModel
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">string</span> LocalData <span style="color: #000000;">&#123;</span> get<span style="color: #008000;">;</span> set<span style="color: #008000;">;</span> <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
&nbsp;
    <span style="color: #000000;">&#91;</span>HandleError<span style="color: #000000;">&#93;</span>
    <span style="color: #0600FF;">public</span> <span style="color: #FF0000;">class</span> HomeController <span style="color: #008000;">:</span> BaseController
    <span style="color: #000000;">&#123;</span>
        <span style="color: #0600FF;">public</span> ActionResult Index<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            ViewData<span style="color: #000000;">&#91;</span><span style="color: #008000;">&amp;</span>quot<span style="color: #008000;">;</span>Message<span style="color: #008000;">&amp;</span>quot<span style="color: #008000;">;</span><span style="color: #000000;">&#93;</span> <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;Welcome to ASP.NET MVC!&quot;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> View<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
&nbsp;
        <span style="color: #0600FF;">public</span> ActionResult About<span style="color: #000000;">&#40;</span><span style="color: #000000;">&#41;</span>
        <span style="color: #000000;">&#123;</span>
            var _formData <span style="color: #008000;">=</span> <span style="color: #008000;">new</span> HomeFormViewModel <span style="color: #000000;">&#123;</span>LocalData <span style="color: #008000;">=</span> <span style="color: #666666;">&quot;I have set this in the Home Controller&quot;</span><span style="color: #000000;">&#125;</span><span style="color: #008000;">;</span>
&nbsp;
            <span style="color: #0600FF;">return</span> View<span style="color: #000000;">&#40;</span>_formData<span style="color: #000000;">&#41;</span><span style="color: #008000;">;</span>
        <span style="color: #000000;">&#125;</span>
    <span style="color: #000000;">&#125;</span>
<span style="color: #000000;">&#125;</span></pre></td></tr></table></div>

<p>&#160;</p>
<p>When the About Action is called the&#160; <strong>HomeFormViewModel</strong>&#160; is populated and then caught by the BaseController <strong>OnActionExecuted</strong> method which injects the required data into the HomeFormViewModel which is derived from <strong>BaseFormViewModel</strong></p>
<p>In About.aspx</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
</pre></td><td class="code"><pre class="asp" style="font-family:monospace;"><span style="color: #006600; font-weight: bold;">&lt;</span> <span style="color: #006600; font-weight: bold;">%@</span> Page Language<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;C#&quot;</span> MasterPageFile<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;~/Views/Shared/Site.Master&quot;</span> Inherits<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;System.Web.Mvc.ViewPage&lt;HomeFormViewModel&gt;&quot;</span> <span style="color: #000000; font-weight: bold;">%&gt;</span>
&nbsp;
<span style="color: #006600; font-weight: bold;">&lt;</span> <span style="color: #006600; font-weight: bold;">%@</span> Import Namespace<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;GlobalViewData.Controllers&quot;</span> <span style="color: #000000; font-weight: bold;">%&gt;</span>
<span style="color: #006600; font-weight: bold;">&lt;</span>asp <span style="color: #006600; font-weight: bold;">:</span>Content ID<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;aboutTitle&quot;</span> ContentPlaceHolderID<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;TitleContent&quot;</span> runat<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;server&quot;</span><span style="color: #006600; font-weight: bold;">&gt;</span>
    About Us
<span style="color: #006600; font-weight: bold;">&lt;/</span>asp<span style="color: #006600; font-weight: bold;">&gt;</span>
<span style="color: #006600; font-weight: bold;">&lt;</span>asp <span style="color: #006600; font-weight: bold;">:</span>Content ID<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;aboutContent&quot;</span> ContentPlaceHolderID<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;MainContent&quot;</span> runat<span style="color: #006600; font-weight: bold;">=</span><span style="color: #cc0000;">&quot;server&quot;</span><span style="color: #006600; font-weight: bold;">&gt;</span>
    <span style="color: #006600; font-weight: bold;">&lt;</span>h2<span style="color: #006600; font-weight: bold;">&gt;</span>
        About<span style="color: #006600; font-weight: bold;">&lt;/</span>h2<span style="color: #006600; font-weight: bold;">&gt;</span>
    <span style="color: #006600; font-weight: bold;">&lt;</span>p<span style="color: #006600; font-weight: bold;">&gt;</span>
        <span style="color: #990099; font-weight: bold;">Global</span> - From BaseController
        <span style="color: #006600; font-weight: bold;">&lt;</span> <span style="color: #006600; font-weight: bold;">%=</span>Html.<span style="color: #9900cc;">Encode</span><span style="color: #006600; font-weight:bold;">&#40;</span>Model.<span style="color: #9900cc;">MyData</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">%&gt;</span>
    <span style="color: #006600; font-weight: bold;">&lt;/</span>p<span style="color: #006600; font-weight: bold;">&gt;</span>
    <span style="color: #006600; font-weight: bold;">&lt;</span>p<span style="color: #006600; font-weight: bold;">&gt;</span>
        Local - From HomeController
        <span style="color: #006600; font-weight: bold;">&lt;</span> <span style="color: #006600; font-weight: bold;">%=</span>Html.<span style="color: #9900cc;">Encode</span><span style="color: #006600; font-weight:bold;">&#40;</span>Model.<span style="color: #9900cc;">LocalData</span><span style="color: #006600; font-weight:bold;">&#41;</span> <span style="color: #000000; font-weight: bold;">%&gt;</span>
    <span style="color: #006600; font-weight: bold;">&lt;/</span>p<span style="color: #006600; font-weight: bold;">&gt;</span>
<span style="color: #006600; font-weight: bold;">&lt;/</span>asp<span style="color: #006600; font-weight: bold;">&gt;</span></pre></td></tr></table></div>

<p><strong></strong></p>
<p><strong>As you can see from the image below the data is populated.</strong></p>
<p><strong></strong></p>
<p><strong></strong></p>
<p><a href="http://agilefutures.com/wp-content/uploads/2009/06/image.png"><img style="border-right-width: 0px; display: inline; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px" title="image" border="0" alt="image" src="http://agilefutures.com/wp-content/uploads/2009/06/image-thumb.png" width="244" height="113" /></a></p>
<p><strong>Hope this is useful!</strong></p>
]]></content:encoded>
			<wfw:commentRss>http://agilefutures.com/index.php/2009/06/mvc-strongly-typed-global-viewdata/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>Adventures in MVC.NET</title>
		<link>http://agilefutures.com/index.php/2009/02/adventures-in-mvcnet/</link>
		<comments>http://agilefutures.com/index.php/2009/02/adventures-in-mvcnet/#comments</comments>
		<pubDate>Mon, 09 Feb 2009 23:35:07 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[Software]]></category>
		<category><![CDATA[.NET]]></category>
		<category><![CDATA[MVC]]></category>

		<guid isPermaLink="false">http://agilefutures.com/?p=60</guid>
		<description><![CDATA[I have been watching the progress of the new MVC framework for Micrsoft.NET and must say I can&#8217;t wait to start using it. However like all things new I have been waiting for some proper guidance and for the software to get to release status &#8211; which should not be far off (a month or [...]]]></description>
			<content:encoded><![CDATA[<p>I have been watching the progress of the new MVC framework for Micrsoft.NET and must say I can&#8217;t wait to start using it. However like all things new I have been waiting for some proper guidance and for the software to get to release status &#8211; which should not be far off (<a title="a month or so" href="http://weblogs.asp.net/scottgu/archive/tags/MVC/default.aspx" target="_blank">a month or so</a>). Scott Guthrie has been making some excellent post regarding the progress and features of MVC &#8211; <a href="http://weblogs.asp.net/scottgu/archive/tags/MVC/default.aspx" target="_blank">http://weblogs.asp.net/scottgu/archive/tags/MVC/default.aspx</a></p>
<p>I have also being following Rob Conerly series on MVC Storefront <a href="http://blog.wekeroad.com/mvc-storefront " target="_blank">http://blog.wekeroad.com/mvc-storefront</a> which is providing some excellent learing both in TDD and DDD practices apart from the MVC framework, I suggest anyone looking at .NET development with or without the MVC part check out and watch the series, you&#8217;ll learn at lot. The series up to EP 23 is published here - <a href="http://www.asp.net/learn/mvc-videos" target="_blank">http://www.asp.net/learn/mvc-videos</a> the rest can be found on Rob&#8217;s blog.</p>
<p>I have a real work app to write and I&#8217;d like to use MVC so when I start using it I&#8217;ll blog a bit more about it.</p>
<p>Regards</p>
<p>Tobi.</p>
]]></content:encoded>
			<wfw:commentRss>http://agilefutures.com/index.php/2009/02/adventures-in-mvcnet/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

