Where is the PDF? On your local machine, on a web server or stored in a database?
If you are using an <asp:Button or <asp:Hyperlink then you can double click it in design mode to create an event in the code behind. Any code to open the PDF can then be added in the event.
If you have the PDF file on your local machine or stored on a server you can add the path to the button's click event or in the HyperLink's NavigateUrl. You can do something as simple as the following assuming you have acrobat installed.
if (navigator.plugins && navigator.plugins.length)
{
for ( var x = 0, l = navigator.plugins.length; x < l; ++x )
{
if (navigator.plugins[x].description.indexOf('Adobe Acrobat') != -1)
{
acrobat.version=parseFloat(navigator.plugins[x].description.split('Version ')[1]);
if (acrobat.version.toString().length == 1) acrobat.version+='.0';
acrobat.installed=true;
break;
}
}
}
else if (window.ActiveXObject)
{
for (x=2; x<10; x++)
{
try
{
oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
if (oAcro)
{
acrobat.installed=true;
acrobat.version=x+'.0';
}
}
catch(e) {}
}
I was able to get Process.Start() to work in VS2005 built-in server but not IIS. I tried many options using Process.StartInfo but no luck. Have you been able to get this to work in IIS?
i got your codes benificiary for my problem, but i have a question regarding the Server.MapPath(?) there if i give the Pdf name, then it shows the same PDf file for all of my records in my gridveiw, instead, i want to have a folder which will be containing
all the PDF files for each single record, and i want the LinkField to open an aproperiate PDF file for a specific Record!
kanaghaaj
Member
2 Points
5 Posts
Open PDF file on button click or hyperlink from asp.net
Feb 14, 2008 12:52 PM|LINK
I want to open a .PDF file on button click or hyperlink.
please help me.
markarmitage
Member
746 Points
141 Posts
Re: Open PDF file on button click or hyperlink from asp.net
Feb 14, 2008 03:24 PM|LINK
Where is the PDF? On your local machine, on a web server or stored in a database?
If you are using an <asp:Button or <asp:Hyperlink then you can double click it in design mode to create an event in the code behind. Any code to open the PDF can then be added in the event.
lspence
Star
11493 Points
1707 Posts
Re: Open PDF file on button click or hyperlink from asp.net
Feb 14, 2008 03:35 PM|LINK
If you have the PDF file on your local machine or stored on a server you can add the path to the button's click event or in the HyperLink's NavigateUrl. You can do something as simple as the following assuming you have acrobat installed.
Response.Redirect("~/somePDFFile.pdf");http://Lspence.blogspot.com
(Please MARK this post as ANSWERED, if you find it helpful)
Haissam
All-Star
37421 Points
5632 Posts
Re: Open PDF file on button click or hyperlink from asp.net
Feb 14, 2008 03:44 PM|LINK
If you mean you want to allow the user to view the file check below link
Download files in ASP.NET
HC
MCAD.NET
| Blog |
bnarasimha
Member
304 Points
67 Posts
Re: Open PDF file on button click or hyperlink from asp.net
Feb 14, 2008 03:53 PM|LINK
Try
Process.Start("pdffile.pdf") ;
"Mark as Answer" the post which helped you in solving your problem
kanaghaaj
Member
2 Points
5 Posts
Re: Open PDF file on button click or hyperlink from asp.net
Feb 15, 2008 04:26 AM|LINK
what if i dont have acrobat installed? will it automatically download acrobat?
Suprotim Aga...
All-Star
15503 Points
1973 Posts
MVP
Re: Open PDF file on button click or hyperlink from asp.net
Feb 15, 2008 04:53 AM|LINK
Hi,
Here's some script used from dithered.com
<script language="javascript">
function detectAcrobat()
{
var acrobat=new Object();
acrobat.installed=false;
acrobat.version='0.0';
if (navigator.plugins && navigator.plugins.length)
{
for ( var x = 0, l = navigator.plugins.length; x < l; ++x )
{
if (navigator.plugins[x].description.indexOf('Adobe Acrobat') != -1)
{
acrobat.version=parseFloat(navigator.plugins[x].description.split('Version ')[1]);
if (acrobat.version.toString().length == 1) acrobat.version+='.0';
acrobat.installed=true;
break;
}
}
}
else if (window.ActiveXObject)
{
for (x=2; x<10; x++)
{
try
{
oAcro=eval("new ActiveXObject('PDF.PdfCtrl."+x+"');");
if (oAcro)
{
acrobat.installed=true;
acrobat.version=x+'.0';
}
}
catch(e) {}
}
try
{
oAcro4=new ActiveXObject('PDF.PdfCtrl.1');
if (oAcro4)
{
acrobat.installed=true;
acrobat.version='4.0';
}
}
catch(e) {}
try
{
oAcro7=new ActiveXObject('AcroPDF.PDF.1');
if (oAcro7)
{
acrobat.installed=true;
acrobat.version='7.0';
}
}
catch(e) {}
}
alert(acrobat.installed);
alert(acrobat.version);
}
</script>
Check the version and redirect the user to the approriate location if adobe is not installed. AFAIK, this code is not 'truly' cross-browser.
HTH,
Suprotim Agarwal
-----
http://www.dotnetcurry.com
http://www.sqlservercurry.com
-----
Free Magazine for ASP.NET Developers
sueBee2
Member
2 Points
1 Post
Re: Open PDF file on button click or hyperlink from asp.net
Feb 22, 2009 01:14 AM|LINK
I was able to get Process.Start() to work in VS2005 built-in server but not IIS. I tried many options using Process.StartInfo but no luck. Have you been able to get this to work in IIS?
Mohammed Ask...
Contributor
2370 Points
535 Posts
Re: Open PDF file on button click or hyperlink from asp.net
Nov 27, 2009 06:07 AM|LINK
(http://support.microsoft.com/directory/article.asp?ID=KB;EN-US;q306654&lex).
http://askarnet.wordpress.com
RMhelaman
Member
6 Points
5 Posts
Re: Open PDF file on button click or hyperlink from asp.net
Jan 20, 2010 04:56 AM|LINK
Hello Ispence!
i got your codes benificiary for my problem, but i have a question regarding the Server.MapPath(?) there if i give the Pdf name, then it shows the same PDf file for all of my records in my gridveiw, instead, i want to have a folder which will be containing all the PDF files for each single record, and i want the LinkField to open an aproperiate PDF file for a specific Record!
thanks in Advance