<?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; ReportServerResult</title>
	<atom:link href="http://agilefutures.com/index.php/tag/reportserverresult/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>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>
	</channel>
</rss>

