Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: Javascript file
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 17-Feb-11 18:20pm
Edited 17-Feb-11 18:23pm
v2
Comments
Sandeep Mewara at 18-Feb-11 0:14am
   
Winforms and Javascript? Sure?

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
string pdfFileName = "C:\\mypdfFileName.pdf";
System.Diagnostics.Process.Start(pdfFileName);
 
c#.net;
 
Response.Write("<SCRIPT language="javascript">var pdf=window.open('" +
result + "','PDF');pdf.moveTo(0,0);</SCRIPT>");
 
or
 
<script type="text/javascript">
function openWindow(path)
{
var myWin = window.open(' " + pdfFileName + " ','mywindow','width=400,height=200');
}
</script>
...
<input type="button" onClick="openWindow(varName)">
  Permalink  
v4
Comments
venkatrao palepu at 17-Feb-11 23:39pm
   
Thank you so much.
 
your code is working fine..
 
is there anyway to open pdf file from javascript..?
orc_orc_orc at 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.
AlbinAbel at 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 at 18-Feb-11 0:15am
   
Good answer. Provided samples for both Winforms(using Process) and ASP.NET(using Javascript)
orc_orc_orc at 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.
Sandeep Mewara at 18-Feb-11 0:39am
   
Agreed! Already posted as a comment to OP.
venkatrao palepu at 18-Feb-11 0:23am
   
Hi
 
while executing it showing error object expected.
 
<script type="text/javascript">
function openWindow(path)
{
var myWin = window.open(' " + pdfFileName + " ','mywindow','width=400,height=200');
}
</script>
...
<input type="button" önClick="openWindow(varName)">
 

Here "varName" means...?
 
Thanks
Venkat
arindamrudra at 18-Feb-11 0:24am
   
Thanks a lot. Great answer with great example.
JF2015 at 18-Feb-11 0:52am
   
Good answer. 5+

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

  Print Answers RSS
0 OriginalGriff 277
1 BillWoodruff 205
2 Maciej Los 205
3 DamithSL 165
4 Sergey Alexandrovich Kryukov 145
0 OriginalGriff 5,107
1 DamithSL 4,157
2 Maciej Los 3,595
3 Kornfeld Eliyahu Peter 3,450
4 Sergey Alexandrovich Kryukov 2,741


Advertise | Privacy | Mobile
Web04 | 2.8.141216.1 | Last Updated 18 Feb 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100