Inline ReportViewer PDF cant open hyperlinks in new window - asp.net

I have a old report generated by ReportViewer in a webpage (Asp.Net). Changed so it's possible to genererate the report as a inline PDF in the same window via:
byte[] bytes = Master.ReportViewer.LocalReport.Render(
"PDF", deviceInfo, out mimeType, out encoding,
out extension,
out streamids, out warnings);
Response.ClearHeaders();
Response.ClearContent();
Response.Clear();
Response.ContentType = mimeType;
Response.AddHeader("Content-Disposition", "inline; filename=Report." + extension);
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
Purpose: Large reports tend to make the webpage unresponsive. The inline PDF don't have the same problem.
Problem: Hyperlinks can only open in the same window.
Anyone had the same problem? or has a simple solution?

How is your link look like?
Did you set up target of your hyperlink to "_blank"?

Related

Getting jibberish when attempting to open DOCX in a browser

Using a memory stream & the correct MIME type with Response.ContentType. Special characters are displayed instead of prompting to open a Word document. I'm using:
using (MemoryStream ms = new MemoryStream())
{
doc.SaveAs(ms);
Response.Clear();
Response.AddHeader("Content-Disposition", string.Format("attachment; filename={0}", fileName));
Response.ContentType = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
ms.WriteTo(Response.OutputStream);
Response.End();
}
Here's an example of the output I get now rather than a prompt to open a Word document:
Turns out it was not a MIME or Response.ContentType issue at all. Being an MVC application, I was attempting to open the FileResult in a modal. Copy/Paste fail, as other buttons worked this way to display content. Not a Word document!

How to disable download pop up in browser from c# .Net

I have added pdf download to my application. When i click on download, browser is asking for whether to save or open the pdf document. But i need to set open as default so that it will not prompt for next time.
Here is my code:
Response.ContentType = "application/pdf";
Response.AppendHeader("Content-Disposition","attachment; filename=" + "Report.pdf");
Response.TransmitFile(pdfFileName);
You can't control that, it's in the scope of your clients browser to deal with that.
Hope it will help u.
Convert the attach file into buffer firstly..
Byte[] buffer = client.DownloadData(path);
if (buffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
}

Open pdf in browser with different names

My program generates PDF in Browser (open the PDF in the browser). But when I want save the file in computer, the default name of PDF is always the same (the name of my class).
I want to pass the name for different pdf's... This is my code:
protected void displayPDF(string filePath, string filename)
{
Response.Clear();
Response.ContentType = "Application/PDF";
//what i do with filename?
Response.WriteFile(filePath);
Response.Flush();
Response.End();
}
I tried this:
Response.AddHeader("Content-Disposition", "attachment; filename=myfile.pdf");
But this way, pdf doesn't open in browser, pass like an attachment.
Can you help me?
Thanks.
Try HttpResponse.TransmitFile(path) eg.
http://bojanskr.blogspot.ca/2012/03/providing-file-for-download-trough-save.html?m=1

Why cant opened downloaded docx files ,in asp.net?

I try to download a docx file from serverside.
What is my wrong ?
this is code :
FileInfo file = new FileInfo(filepath);
Response.Clear();
Response.ClearHeaders();
Response.ClearContent();
Response.AppendHeader("Content-Disposition", "attachment; filename = " + ((Button)sender).CommandName + ".docx");
Response.AppendHeader("Content-Length", file.Length.ToString());
Response.ContentType = "application/octet-stream";
Response.WriteFile(file.FullName);
Response.Flush();
Response.Close();
Response.End();
I have posted something similar in another question for an PDF but here goes. It's much easier to stream this sort of data back through an ASHX handler.
Something like what I posted in this question but with a docx file.
Display PDF in iframe
It looks like you are using a normal ASP.NET page and are trying to modify the standard behavior by clearing out the headers, etc. You won't have to fiddle with the headers or anything like that with an ashx handler.

ASP.Net page export to pdf

I got stuck with my ASP.Net export to PDF. Below are my codes. Please help.
Response.Clear();
Response.Buffer = true;
Response.Charset = Encoding.UTF8.HeaderName;
Response.ContentEncoding = Encoding.UTF8;
Response.Write(string.Format("<meta http-equiv=Content-Type content=text/html;charset={0}>", Encoding.UTF8.HeaderName));
Response.ContentType = "application/pdf";
Response.Headers.Add("Content-disposition", "attachment; filename=pdffilename.pdf");
StringBuilder sb = new StringBuilder();
sb.Append("MIME-Version: 1.0\r\n");
sb.Append("X-Document-Type: Worksheet\r\n");
sb.Append("Content-Type: multipart/related; boundary=\"----=mtrSystem\"\r\n\r\n\r\n");
sb.Append("------=mtrSystem\r\n");
sb.Append("Content-Type: text/html; charset=\"utf-8\"\r\n");
sb.Append("<html xmlns:o=\"urn:schemas-microsoft-com:office:office\"\r\n");
sb.Append("xmlns:x=\"urn:schemas-microsoft-com:office:pdf\">\r\n\r\n\r\n");
sb.Append("------=mtrSystem\r\n");
sb.Append("Content-ID: baiduimg\r\n");
sb.Append("Content-Transfer-Encoding: base64\r\n");
sb.Append("Content-Type: image/png\r\n\r\n");
Can i use this way to export my ASP.Net page to PDF?
Html-to-pdf.net allows for converting html to pdf. TO get the html from an asp.net page, use the following code:
StringWriter sw = new StringWriter();
Server.Execute("PageToConvert.aspx", sw);
string htmlCodeToConvert = sw.GetStringBuilder().ToString();
Then pass the html to the pdf generator:
public byte[] GetPdfBytesFromHtmlString (string htmlString)
You can then save the bytes to the response to send to client, or save on the server as a local file.
EDIT:
Something to keep in mind, html-to-pdf does cost money, but for my last project it was a justified expense. You can use the trial version to figure out what you needd.
I'm not entirely sure what you're trying to do, but generally I can highly recommend PDFSharp for creating PDF documents in code...

Resources