Open a pdf document on the page load

Posted by Vasudevula under C# on 12/20/2011 | Points: 10 | Views : 1895 | Status : [Member] | Replies : 1
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("<script>window.open('file:" + Path.Replace("\\", "/") + "')'</script>");
}
}
else
Response.Write("<script>alert('Document has not been created yet'); </script>");




In the above code there are two problems
1) I could not show the pdf document on the page.When the page opens i only see the blank page opened with no pdf document opened.
2) In the else loop if the document doesnot exist then i need to display the message and close the current page.




Responses

Posted by: Gow.net on: 12/20/2011 [Member] Starter | Points: 25

Up
0
Down
try this http://www.codeproject.com/KB/files/xpdf_csharp.aspx

gowthaman8870226416

Vasudevula, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response