Open a pdf document on the page load

Posted by Vasudevula under C# on 12/20/2011 | Points: 10 | Views : 1954 | 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;
fs = File.Open(Path, FileMode.Open, FileAccess.ReadWrite, FileShare.None);
catch (IOException)
bool canRead = fs.CanRead;
if (canRead)
Response.Write("<script>'file:" + Path.Replace("\\", "/") + "')'</script>");
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.


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

try this


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

Login to post response