Click here to Skip to main content
15,887,416 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi
i created one PDF file in my "C" Folder.

when the user click on "button", i want to open that "PDF file".


Please help me..
Posted
Updated 17-Feb-11 17:23pm
v2
Comments
Sandeep Mewara 18-Feb-11 0:14am    
Winforms and Javascript? Sure?

1 solution

Well in 2 lines of code you can do that assuming you have acrobat reader installed in your computer. System.Diagnostics namespace has a process class to do this.

add
using System.Diagnostics;



Place this code to your button click event.
MIDL
string pdfFileName = "C:\\mypdfFileName.pdf";
System.Diagnostics.Process.Start(pdfFileName);


c#.net;

XML
Response.Write("<SCRIPT language=javascript>var pdf=window.open('" +
result + "','PDF');pdf.moveTo(0,0);</SCRIPT>");


or

XML
<script type="text/javascript">
function openWindow(path)
{
var myWin = window.open(' " + pdfFileName + " ','mywindow','width=400,height=200');
}
</script>
...
<input type="button" onClick="openWindow(varName)">
 
Share this answer
 
v4
Comments
venkatrao palepu 17-Feb-11 23:39pm    
Thank you so much.

your code is working fine..

is there anyway to open pdf file from javascript..?
Orcun Iyigun 18-Feb-11 0:08am    
i am confused C# or C#.net platform? if it is C# there wont be a client side and if it is C#.net I can revise the answer. Because Process.Start wont work in client side in C#.net.
Albin Abel 17-Feb-11 23:57pm    
Javascript runs at client side. If this is allowed then it will be security issue. So I think it is not allowed.
Sandeep Mewara 18-Feb-11 0:15am    
Good answer. Provided samples for both Winforms(using Process) and ASP.NET(using Javascript)
Orcun Iyigun 18-Feb-11 0:20am    
Thanks :) But I think the subject of the thread has to be changed because it is not appropriate winforms and javascript.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900