Forums

This topic is locked

Force .doc link to open in word not browser

Posted 24 Mar 2005 16:01:49
1
has voted
24 Mar 2005 16:01:49 Ronan Donohoe posted:
Hi,
can anyone tell me how to force a link in a page to a .doc file to open in Word and not in the browser.
This would produce an open/download dialoge box.

Thanks
Ro

Replies

Replied 24 Mar 2005 17:00:06
24 Mar 2005 17:00:06 Lee Diggins replied:
Hi Ronan

To force a download of a Word doc, here's two pages to do it for you.

Page One = page with link to page two

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>Untitled Document</title>
</head>

<body>
<a href="download_go.asp">Download File</a>
</body>
</html>

Page Two = page with code to force download of doc:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
Dim objStream, myContents, myFileName

myFileName = "download_doc.doc" 'change the name to suit

Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename=" & myFileName

Set objStream = Server.CreateObject("ADODB.Stream"

objStream.Open
objStream.LoadFromFile Server.MapPath(myFileName) 'again change to suit if needed
myContents = objStream.ReadText

Response.BinaryWrite myContents

objStream.Close
Set objStream = Nothing
%>

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
&lt;font size="1"&gt;[ Studio MX/MX2004 | ASP -&gt; VBScript/PerlScript/JavaScript | SQL | CSS ]&lt;/font&gt;

Edited by - Digga the Wolf on 24 Mar 2005 17:00:45
Replied 24 Mar 2005 18:51:56
24 Mar 2005 18:51:56 Ronan Donohoe replied:
Thanks! Thats exactly what i needed.

Ro
Replied 20 Mar 2006 09:39:15
20 Mar 2006 09:39:15 Aasim Momin replied:
I am having the same problem but would like the functionality on a CD. The word documents would be present on the cd as well as the flash file trying to open the word files. How could i achieve it?

-Aasim
Replied 08 Sep 2006 21:46:33
08 Sep 2006 21:46:33 Martin Hofmann replied:
<BLOCKQUOTE id=quote><font size=1 face="Verdana, Arial, Helvetica" id=quote>quote:<hr height=1 noshade id=quote>
Hi Ronan

To force a download of a Word doc, here's two pages to do it for you.

Page One = page with link to page two

&lt;%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%&gt;
&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "www.w3.org/TR/html4/loose.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;title&gt;Untitled Document&lt;/title&gt;
&lt;/head&gt;

&lt;body&gt;
&lt;a href="download_go.asp"&gt;Download File&lt;/a&gt;
&lt;/body&gt;
&lt;/html&gt;

Page Two = page with code to force download of doc:

&lt;%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%&gt;
&lt;%
Dim objStream, myContents, myFileName

myFileName = "download_doc.doc" 'change the name to suit

Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename=" & myFileName

Set objStream = Server.CreateObject("ADODB.Stream"

objStream.Open
objStream.LoadFromFile Server.MapPath(myFileName) 'again change to suit if needed
myContents = objStream.ReadText

Response.BinaryWrite myContents

objStream.Close
Set objStream = Nothing
%&gt;

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
&lt;font size="1"&gt;[ Studio MX/MX2004 | ASP -&gt; VBScript/PerlScript/JavaScript | SQL | CSS ]&lt;/font&gt;

Edited by - Digga the Wolf on 24 Mar 2005 17:00:45
<hr height=1 noshade id=quote></BLOCKQUOTE id=quote></font id=quote><font face="Verdana, Arial, Helvetica" size=2 id=quote>


Thanks!

I modified it so I can just send a variable from the link and only have to create one download.asp page instead of separate ones for my hundreds of files to be downloaded.


&lt;%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%&gt;
&lt;%
Dim objStream, myContents, myFileName

'send filename variable through link on separate page:
'download.asp?myFileName=somepath/somefile.ext

'Read the file name form variable. We will use CStr
'to make sure we are getting a string.
myFileName = CStr(Request("myFileName")


Response.ContentType = "application/octet-stream"
Response.AddHeader "content-disposition", "attachment; filename=" & myFileName

Set objStream = Server.CreateObject("ADODB.Stream"

objStream.Open
objStream.LoadFromFile Server.MapPath(myFileName) 'again change to suit if needed
myContents = objStream.ReadText

Response.BinaryWrite myContents

objStream.Close
Set objStream = Nothing
%&gt;
Replied 14 Sep 2006 08:34:53
14 Sep 2006 08:34:53 Sophia Li replied:
Is a way to force download files loacted on the other server? For example, download.asp is located at www.myserver.com and the file to be downloaded is www.onlineaudio.com/audio/test.mp3? Thanks.
Replied 05 Mar 2007 14:16:14
05 Mar 2007 14:16:14 Marcus Bennick replied:
I want my users to click on a wordlink on my website, and then the word doc. shall open in the office word and not in the browser. I have tried to insert the code you postet, but I cant get it to work. Can you maybe exoplain it for e newbee.
Offcourse I have upoloaded the word doc to my webplace
Replied 06 Mar 2007 22:43:52
06 Mar 2007 22:43:52 Lee Diggins replied:
Hi Marcus

This is a setting controlled by your operating system, you can make the change by following these instructions:

support.microsoft.com/kb/162059

Sharing Knowledge Saves Valuable Time!!!
~ ~ ~ ~ ~ ~
<b>Lee Diggins</b> - <i>DMXzone Manager</i>
<font size="1">[ Studio MX/MX2004 | ASP -> VBScript/PerlScript/JavaScript | SQL | CSS ]</font>

Reply to this topic