Click here to Skip to main content
13,148,136 members (44,792 online)
Rate this:
Please Sign up or sign in to vote.
See more:

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
Updated 17-Feb-11 17:23pm
Sandeep Mewara 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 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 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 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)
orc_orc_orc 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 18-Feb-11 0:39am
Agreed! Already posted as a comment to OP.
venkatrao palepu 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 18-Feb-11 0:24am
Thanks a lot. Great answer with great example.
JF2015 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
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web03 | 2.8.170924.1 | Last Updated 18 Feb 2011
Copyright © CodeProject, 1999-2017
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