Click here to Skip to main content
11,715,160 members (60,317 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: Javascript file

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 17:20pm
Edited 17-Feb-11 17:23pm
Sandeep Mewara at 18-Feb-11 0:14am
Winforms and Javascript? Sure?

1 solution

Rate this: bad
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.

using System.Diagnostics;

Place this code to your button click event.
string pdfFileName = "C:\\mypdfFileName.pdf";

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


<script type="text/javascript">
function openWindow(path)
var myWin =' " + pdfFileName + " ','mywindow','width=400,height=200');
<input type="button" onClick="openWindow(varName)">
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 platform? if it is C# there wont be a client side and if it is I can revise the answer. Because Process.Start wont work in client side in
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

while executing it showing error object expected.

<script type="text/javascript">
function openWindow(path)
var myWin =' " + pdfFileName + " ','mywindow','width=400,height=200');
<input type="button" önClick="openWindow(varName)">

Here "varName" means...?

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 Sergey Alexandrovich Kryukov 495
1 Richard MacCutchan 275
2 Maciej Los 259
3 ManasKumarM 155
4 Frankie-C 125
0 Sergey Alexandrovich Kryukov 775
1 CHill60 415
2 Richard MacCutchan 405
3 Maciej Los 389
4 OriginalGriff 320

Advertise | Privacy | Mobile
Web04 | 2.8.150901.1 | Last Updated 18 Feb 2011
Copyright © CodeProject, 1999-2015
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