Hi Mudassar, I used the instructions you gave in "Create PDF Report from database in ASP.Net using C# and VB.Net" to create a PDF from SQL query. The PDF is generated and I can download it when I click the 'Generate' button. But I want the stream file to be shown in the embed PDF viewer which is inside a DIV instead of propmting me to save it or to open it directly in the browser. This other instructions "Convert Binary data to PDF file in C# and VB.Net" may be similar to what I am looking, but does not solve my issue, because you use an index called "Id", which looks like it is tied to the SQL query. The other thing I noticed is that you use ResolveUrl("~/FileVB.ashx?Id=") to read the file. Can it be bypassed? I am not very much familiar with the use of ashx file. Since my code already generates the PDF, how can it be redirected to the embed viewer and not the browser? Any idea?
I am reusing your code, so this is what I have so far:
string reportLabel = lbReports.Text;
document.Add(table);
document.Close();
byte[] bytes = memoryStream.ToArray();
Response.Clear();
Response.AddHeader("Content-Disposition", "inline");
Response.Buffer = true;
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.BinaryWrite(bytes);
string embed = "<object data=\"{0}\" type=\"application/pdf\" width=\"698px\" height=\"450px\">";
embed += "If you are unable to view file, you can download from <a href = \"{0}\">here</a>";
embed += " or download <a target = \"_blank\" href = \"http://get.adobe.com/reader/\">Adobe PDF Reader</a> to view the file.";
embed += "</object>";
ltEmbed.Text = string.Format(embed, ("blabla.pdf")); /*it shows this PDF as local file just for test*/
memoryStream.Close();
this.Context.ApplicationInstance.CompleteRequest();
The idea is to have the generated file to be displayed inside the viewer in the DIV. In other words, I am looking to display the dynamic PDF file using ltEmbed.Text = string.Format(embed, ...);