Posted by pareshjagatia on May 3, 2008
The following code helps exporting the Report into PDF and Excel formats using the Render method of the ServerReport. Use below code after the report is loaded (refresh() is called on the reportviewer control).
1 string mimeType;
2 string encoding;
3 string fileNameExtension;
4 Warning[] warnings;
5 string[] streamids;
6 byte[] exportBytes = reportViewer.ServerReport.Render(“PDF“, null, out mimeType, out encoding, out fileNameExtension, out streamids, out warnings);
7 HttpContext.Current.Response.Buffer = true;
8 HttpContext.Current.Response.Clear();
9 HttpContext.Current.Response.ContentType = mimeType;
10 HttpContext.Current.Response.AddHeader(“content-disposition“, “attachment; filename=ExportedReport.“ + fileNameExtension);
11 HttpContext.Current.Response.BinaryWrite(exportBytes);
12 HttpContext.Current.Response.Flush();
13 HttpContext.Current.Response.End();
To get Excel file use “Excel” as the parameter in the Render method.
Sometimes you might need to send the Report content into email. To Achieve this you can use the above code where you need to pass “HTML4.0” as the first parameter to the Render method. After you get the byte array from the Render method you can convert it to string as below
2 1 string mimeType;
2 string encoding;
3 Warning[] warnings;
4 string[] streamids;
5 string fileNameExtension;
6 byte[] htmlBytes = PerksReportViewer.ServerReport.Render(“HTML4.0“, null, out mimeType, out encoding, out fileNameExtension, out streamids, out warnings);
7 string reportHtml = System.Text.Encoding.UTF8.GetString(htmlBytes);
8 return reportHtml;
Posted in ASP.NET, SSRS - Sql Server Reporting Services | Tagged: SSRS - Sql Server Reporting Services | No Comments »
Posted by pareshjagatia on May 1, 2008
Once I had a call from my boss saying “Can you tell me if we have used any Favicon file in our website in any page or somewhere? As if we have used it, the file is not in place. Look at this IIS log it is full of 404s for the same file.”. And I was absolutely blank about this name. I opened the project and fired “Find in solution” but did not get any FavIcon reference.
Huh, a file that is not referenced anywhere in your website and still your IIS has 404 enteries? Later on I came to know that this is the file that is being shown into the address bar and in the favourites list in most browsers. More information about FavIcon can be found here.
And be sure to keep the Favicon file small in size to avoid high bandwidth usage, check this out on Scott’s Blog. But keep this file atleast to save 404 in your IIS log. One other file is Robots.txt that, I am not pretty sure, puts 404 in your IIS log when not found by the crawlers. You can check it out.
Posted in ASP.NET, HTML, IIS | Tagged: FavIcon, HTTP 404, IIS | 1 Comment »
Posted by pareshjagatia on May 1, 2008
There are email capture programs that grabs email addresses from web pages. Even you can write one for you using the WebClient and from the ResponseText put the regular expression to capture email.
Now a days there are some tools that makes you image for your email address to make your email address safe from the above kind of programs. But the solution is when the text is controlled by you. What if you are having a Content Management Solution and people are creating pages using the HTML editors and they put email address into the editor? Or say you have a lot of email addresses to convert, its a headache.
Let us not allow the email capture programs to grab text email addresses from our websites.
Please refer to this post on my another Post on the Blogger. As the ascii encoded text in the example is not working with the HTML Editor used in the WordPress post writer.
Happy Programming…!!!
Posted in ASP.NET, HTML, Security | Tagged: ASP.NET, HTML, Security | No Comments »