Hi Experts
I am trying to open a pdf document in a aspx page but i dont know what is the mistake i made in the following code.
string Path = Request.QueryString["Path"];
if (File.Exists(Path.Replace("pdf", "txt")))
{
FileStream fs = null;
try
{
fs = File.Open(Path, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
}
catch (IOException)
{
}
bool canRead = fs.CanRead;
if (canRead)
{
fs.Close();
Response.Write("");
}
}
else
Response.Write("");
In the above code there are two problems
1) I could not show the pdf document on the page
2) In the else loop if the document doesnot exist then i need to display the message and close the current page.
Any ideas??????????
Loading
karthik vPosted Nov 23, 2011, 12:02 PM
But we have this already programmed in my project so now i will have to see what the problem and rectify this.
Satyapriya NayakPosted Nov 23, 2011, 11:58 AM
Try this...
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Net;
public partial class Default2 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
ReadPdfFile();
}
private void ReadPdfFile()
{
string path = @"d:\a.pdf";
WebClient client = new WebClient();
Byte[] buffer = client.DownloadData(path);
if (buffer != null)
{
Response.ContentType = "application/pdf";
Response.AddHeader("content-length", buffer.Length.ToString());
Response.BinaryWrite(buffer);
}
}
}
Thanks
karthik vPosted Nov 23, 2011, 11:57 AM
i dont see the pdf document opening in the page.It is the webform that is opening and nothing else on the page.....
Rahul MPosted Nov 23, 2011, 11:44 AM