{"id":140,"date":"2008-03-03T10:14:00","date_gmt":"2008-03-03T10:14:00","guid":{"rendered":"\/lisa\/post\/2008\/03\/03\/Report-Preprocessing-SQL-Server-Reporting-Server-Group-PageTotals-Part-II-A-Walkthrough-on-the-Client-Side.aspx"},"modified":"2008-03-03T10:14:00","modified_gmt":"2008-03-03T10:14:00","slug":"report-preprocessing-sql-server-reporting-server-group-pagetotals-part-ii-a-walkthrough-on-the-client-side","status":"publish","type":"post","link":"https:\/\/spacefold.com\/lisa\/2008\/03\/03\/report-preprocessing-sql-server-reporting-server-group-pagetotals-part-ii-a-walkthrough-on-the-client-side\/","title":{"rendered":"Report Preprocessing: SQL Server Reporting Server Group PageTotals, Part II: A Walkthrough on the Client Side"},"content":{"rendered":"<p>\n<a href=\"\/lisa\/2008\/03\/04\/Report-Preprocessing-SQL-Server-Reporting-Server-Group-PageTotals-Walkthrough-Part-I-the-RDL-and-the-Server\/\" title=\"Group PageTotals walkthrough blog post, part 1\">Last time<\/a>, as you remember, we handled the server-side and coding details of a preprocessed report (and gory details they were).&nbsp; You saw that we set up the appropriate information for values that we might need in a preprocess run, and then the right information is available to you on the followup run.\n<\/p>\n<p>\nWhile this technique is useful for the &quot;Group Page Totals&quot; problem under discussion, it is applicable to many more cases.&nbsp; For example, you could apply it to a report that required a table of contents or an index.&nbsp; So even if you don&#39;t need group page totals you might want to give this some thought &#8212; and it&#39;s really a pity that there isn&#39;t an obvious built-in way to tell the RS reporting engine &quot;please do all the work <em>according to the needs of a particular <\/em>renderer, but don&#39;t give me any output, then perform a second run&quot;.&nbsp;\n<\/p>\n<p class=\"NB\">\nThe key thing here is <em>according to the needs of a particular renderer.<\/em> You can provide for a &quot;null output&quot; rendering extension pretty easily; in fact I think there is one built-in to the Report Server configuration file, although it is excluded, by default, from the Export formats that will show up in the drop down.&nbsp; Maybe this type of job is what it&#39;s for.<\/p>\n<p>But you have to render <em>according to a particular export format<\/em>, even when you&#39;re not getting any physical output, to get the pagination that corresponds to that export format.&nbsp; And that&#39;s an entirely different thing.\n<\/p>\n<p>\nSo let&#39;s get to it.\n<\/p>\n<p>\nIn this example, as I explained earlier, I&#39;ve chosen to use an ASP.NET client, but the type of client should not matter. ASP.NET just has one more wrinkle, displaying a PDF appropriately in the browser, so I thought I would include that in my example code.\n<\/p>\n<p>\nI&#39;ve also chosen to access the report using the RS web service, simply because <a href=\"\/lisa\/2007\/09\/20\/Another-bit-for-dynamic-ReportViewer-control-handling-Parameters-in-more-depth\/\" title=\"Blog post about handling parameters in RS URL Access\">in previous examples<\/a> I&#39;ve used URL Access, and I thought it would make a nice change.\n<\/p>\n<p>\nSo let&#39;s say we have two&nbsp;buttons on a web page, looking something like this:\n<\/p>\n<p class=\"code\">\n&lt;input type=&quot;submit&quot; name=&quot;Button1&quot; value=&quot;GetPreprocessedReport&quot; id=&quot;Button1&quot; \/&gt; &amp;nbsp; <br \/>\n&lt;input type=&quot;submit&quot; name=&quot;Button2&quot; value=&quot;GetPDF&quot; id=&quot;Button2&quot; \/&gt;\n<\/p>\n<p>\n&#8230; that&#39;s pretty much it.\n<\/p>\n<p>\nNow we have to write the code under those two buttons.&nbsp; The key thing is pushing the parameters over appropriately for each run (preprocess and &quot;real&quot;), for each type.\n<\/p>\n<p>\nHere&#39;s the code for Button1:\n<\/p>\n<p class=\"code\">\n<span style=\"color: blue\">Protected Sub<\/span> Button1_Click(<span style=\"color: blue\">ByVal<\/span> sender <span style=\"color: blue\">As Object<\/span>, <span style=\"color: blue\">ByVal<\/span> e <span style=\"color: blue\">As<\/span> System.EventArgs) <span style=\"color: blue\">Handles<\/span> Button1.Click&nbsp;<\/p>\n<p>&nbsp;&nbsp;<span style=\"color: green\">&#39;&nbsp;most of the report-accessing code here&nbsp;<\/span> <br \/>\n<span style=\"color: green\">&nbsp;&nbsp;&#39;&nbsp;is pretty much straight out of &nbsp;<\/span> <br \/>\n&nbsp; <span style=\"color: green\">&#39; <a href=\"http:\/\/msdn2.microsoft.com\/en-us\/library\/aa258532(SQL.80)\/\">http:\/\/msdn2.microsoft.com\/en-us\/library\/aa258532(SQL.80)<\/a><\/span> <br \/>\n<span style=\"color: green\">&nbsp;<\/span> <\/p>\n<p>&nbsp; <span style=\"color: blue\">Dim<\/span> rs <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">New<\/span> ReportingService() <br \/>\n&nbsp; rs.Credentials = System.Net.CredentialCache.DefaultCredentials <\/p>\n<p>&nbsp;&nbsp;<span style=\"color: green\">&#39; Let&#39;s add the correct Render arguments<\/span> <br \/>\n&nbsp; <span style=\"color: blue\">Dim<\/span> result <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">Byte<\/span>() = <span style=\"color: blue\">Nothing<\/span> <br \/>\n&nbsp; <span style=\"color: blue\">Dim<\/span> reportPath <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">String<\/span> = <span style=\"color: #a31515\">&quot;\/ReportProject1\/SqlWorldGroupTotals&quot;<\/span> <br \/>\n&nbsp; <span style=\"color: blue\">Dim<\/span> format <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">String<\/span> = <span style=\"color: #a31515\">&quot;HTML4.0&quot;<\/span> <\/p>\n<p>&nbsp; <span style=\"color: green\">&#39; For the real fileKey value<\/span>, <br \/>\n<span style=\"color: green\">&nbsp; &#39;&nbsp;you would want to put something in <\/span><br \/>\n&nbsp; <span style=\"color: green\">&#39; here that uniquely identifies the session and the user,<\/span> <br \/>\n&nbsp; <span style=\"color: green\">&#39; not just the output type as I am doing here&#8230;<\/span>&nbsp;<br \/>\n&nbsp; <span style=\"color: blue\">Dim<\/span> fileKey <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">String<\/span> <br \/>\n&nbsp; fileKey = <span style=\"color: #a31515\">&quot;TestHTML&quot;<\/span> <\/p>\n<p>&nbsp;&nbsp;<span style=\"color: green\">&#39; Prepare report parameters.<\/span> <br \/>\n&nbsp;&nbsp;<span style=\"color: blue\">Dim<\/span> parameters(2) <span style=\"color: blue\">As<\/span> ParameterValue <br \/>\n&nbsp; parameters(0) = <span style=\"color: blue\">New<\/span> ParameterValue() <br \/>\n&nbsp; parameters(0).Name = <span style=\"color: #a31515\">&quot;FileKey&quot;<\/span> <br \/>\n&nbsp; parameters(0).Value = fileKey <br \/>\n&nbsp; parameters(1) = <span style=\"color: blue\">New<\/span> ParameterValue() <br \/>\n&nbsp; parameters(1).Name = <span style=\"color: #a31515\">&quot;PreProcess&quot;<\/span> <br \/>\n&nbsp; parameters(1).Value = <span style=\"color: blue\">True<\/span> <br \/>\n&nbsp; parameters(2) = <span style=\"color: blue\">New<\/span> ParameterValue() <br \/>\n&nbsp; parameters(2).Name = <span style=\"color: #a31515\">&quot;ExportType&quot;<\/span> <br \/>\n&nbsp; parameters(2).Value = <span style=\"color: #a31515\">&quot;HTML&quot;<\/span> <br \/>\n<span style=\"color: blue\">&nbsp; Dim<\/span> sh <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">New<\/span> SessionHeader() <br \/>\n&nbsp; rs.SessionHeaderValue = sh <\/p>\n<p>&nbsp; <span style=\"color: blue\">Try<\/span> <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = rs.Render(reportPath, format, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, parameters, _ <br \/>\n&nbsp;&nbsp; &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>) <br \/>\n<span style=\"color: #008000\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39;&nbsp;We&#39;ve just done the&nbsp;preprocess run. We&#39;re not going to do anything<\/span> <br \/>\n<span style=\"color: #008000\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &#39; with those results, though.<\/span> <\/p>\n<p>&nbsp;&nbsp; &nbsp;&nbsp; sh.SessionId = rs.SessionHeaderValue.SessionId <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<span style=\"color: green\">&#39; Now we&#39;ll render a second time before displaying the results,<\/span> <br \/>\n<span style=\"color: green\">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&#39; letting the report know that we are not in &quot;preprocess&quot; mode this time:<\/span> <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; parameters(1).Value = <span style=\"color: blue\">False<\/span> <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = rs.Render(reportPath, format, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, parameters, _ <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>) <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.OutputStream.Write(result, 0, result.Length) <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; result = <span style=\"color: blue\">Nothing<\/span> <br \/>\n&nbsp; <span style=\"color: blue\">Catch<\/span> ex <span style=\"color: blue\">As<\/span> Exception <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Response.Write(ex.Message()) <br \/>\n&nbsp; <span style=\"color: blue\">End<\/span> <span style=\"color: blue\">Try<\/span> <br \/>\n&nbsp; sh = <span style=\"color: blue\">Nothing<\/span> <br \/>\n&nbsp; rs.Dispose() <br \/>\n&nbsp;&nbsp;rs = <span style=\"color: blue\">Nothing<\/span> <\/p>\n<p><span style=\"color: blue\">End<\/span> <span style=\"color: blue\">Sub<\/span>\n<\/p>\n<p>\nNothing too fancy there.\n<\/p>\n<p>\nAnd, as you can probably figure out, the code for Button2 is almost exactly the same, except for our various parameter values and the Render format, but we&#39;ll also add an appropriate content type so that the browser will display it properly:\n<\/p>\n<p class=\"code\">\n<span style=\"color: blue\">[Excerpted] Protected<\/span> <span style=\"color: blue\">Sub<\/span> Button2_Click( <span style=\"color: blue\">ByVal<\/span> sender <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">Object<\/span>, <span style=\"color: blue\">ByVal<\/span> e <span style=\"color: blue\">As<\/span> System.EventArgs) <span style=\"color: blue\">Handles<\/span> Button2.Click<br \/>\n<span style=\"color: green\">&nbsp; &#39; &#8230; <\/span><br \/>\n&nbsp; fileKey = <span style=\"color: #a31515\">&quot;TestPDF&quot;<\/span> <br \/>\n<span style=\"color: green\">&nbsp; &#39; &#8230; <\/span><br \/>\n&nbsp; <span style=\"color: blue\">Dim<\/span> format <span style=\"color: blue\">As<\/span> <span style=\"color: blue\">String<\/span> = <span style=\"color: #a31515\">&quot;PDF&quot;<\/span> <br \/>\n<span style=\"color: green\">&nbsp; &#39; &#8230; <\/span><br \/>\n&nbsp; parameters(2).Value = <span style=\"color: #a31515\">&quot;PDF&quot;<\/span> <br \/>\n<span style=\"color: green\">&nbsp; &#39; &#8230; we&#39;ll get our second result as before:<\/span> <br \/>\n&nbsp; result = rs.Render(reportPath, format, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, parameters, _ <br \/>\n&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>, <span style=\"color: blue\">Nothing<\/span>) <br \/>\n<span style=\"color: green\">&nbsp; &#39; but then:<\/span> <br \/>\n&nbsp; Response.ContentType = <span style=\"color: #a31515\">&quot;Application\/pdf&quot;<\/span> <br \/>\n<span style=\"color: green\">&nbsp;&nbsp;&#39; followed by the same:<\/span> <br \/>\n&nbsp; Response.OutputStream.Write(result, 0, result.Length) <br \/>\n<span style=\"color: green\">&nbsp; &#39; &#8230; See?<\/span>\n<\/p>\n<p>\nWhen you examine your results in the browser you can clearly see the difference in overall page total for the two rendering targets.\n<\/p>\n<p>\n<img loading=\"lazy\" decoding=\"async\" src=\"\/lisa\/wp-non\/migrated\/ReportPreProcessHTMLandPDFResults.png\" alt=\"Preprocessing results\" title=\"Preprocessing results\" width=\"500\" height=\"331\" align=\"middle\" \/>&nbsp;\n<\/p>\n<p>\nWe&#39;re all done, and it wasn&#39;t too tough, except that I somehow forgot to work in my requirement of <em>at least one Serenity quote per post<\/em>, at least so far.&nbsp; So here&#39;s our <a href=\"http:\/\/www.serenitymovie.com\/\" target=\"_blank\" title=\"Big Damn Movie site\" rel=\"noopener\">Serenity<\/a> thought for the day:\n<\/p>\n<h3>We&#39;ve done the impossible, and that makes us mighty.<\/h3>\n<p>\nDoesn&#39;t hardly seem like this <em>was<\/em> the impossible.\n<\/p>\n<p>\nBut if you look back at <a href=\"\/lisa\/2008\/03\/04\/Report-Preprocessing-SQL-Server-Reporting-Server-Group-PageTotals-Walkthrough-Part-I-the-RDL-and-the-Server\/\" title=\"Group PageTotals walkthrough blog post, part 1\">the previous post<\/a>&nbsp;and put the whole effort together&#8230; you realize that these are words for RS folks to live (and code)&nbsp;by.\n<\/p>\n<p>\n&#39; Til next time.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Last time, as you remember, we handled the server-side and coding details of a preprocessed report (and gory details they were).&nbsp; You saw that we set up the appropriate information for values that we might need in a preprocess run, and then the right information is available to you on the followup run. While this<a class=\"more-link\" href=\"https:\/\/spacefold.com\/lisa\/2008\/03\/03\/report-preprocessing-sql-server-reporting-server-group-pagetotals-part-ii-a-walkthrough-on-the-client-side\/\">Read more<\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,6],"tags":[],"class_list":["post-140","post","type-post","status-publish","format-standard","hentry","category-reporting","category-sql-server"],"_links":{"self":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/140","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/comments?post=140"}],"version-history":[{"count":0,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/posts\/140\/revisions"}],"wp:attachment":[{"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/media?parent=140"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/categories?post=140"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/spacefold.com\/lisa\/wp-json\/wp\/v2\/tags?post=140"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}