Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with File Download

Status
Not open for further replies.

scribbler

MIS
Feb 4, 2002
206
0
0
GB
Can anyone please help me with the following..

I have a need to offer users ability to download a document which, after reading thro' the web, I managed to achieve (no mean feat for a relative newbie to all things web) but what I do at present is link to this page from elsewhere and once the user completes the download it leaves a blank page on screen. To avoid this, I am informed after browsing the javascript forum, I need to link directly to the file rather than to a page but I've no idea how to do this. can anyone point out how to achieve this, if it the correct way to do it or otherwise..

Code:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<%
    path="C:\WhatEverPathIsUsed\test.doc"
    set fso=Server.CreateObject("Scripting.FileSystemObject")
    set f=fso.OpenTextFile(path)
    data=f.ReadAll
    ext=fso.GetExtensionName(path)
    if ext="pdf" then
     Response.ContentType="application/pdf"
    elseif ext="doc" then
     Response.ContentType="application/msword"
    'Response.AddHeader "Content-Disposition"," attachment; filename=" & "test.doc"
        If Request.QueryString("ID")="Business" Then 'Allow Download Of Business Proposal 
            Response.AddHeader "Content-Disposition"," attachment; filename=" & "rc_companyproposal.doc"
            Response.BinaryWrite data
        ElseIf Request.QueryString("ID")="Consumer" Then 'Allow Download Of Consumer Proposal 
            Response.AddHeader "Content-Disposition"," attachment; filename=" & "rc_consumerproposal.doc"
            Response.BinaryWrite data
        End IF
    End if

    Set f = Nothing 
    Set fso = Nothing 
%> 
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<BODY>
</body>
</html>
 
Like asked on the JS forum, why not just provide a direct link to the file, instead of all the fso stuff. Such as:

Code:
<A href="rc_consumerproposal.doc">Consumer Download</a>

Are you trying to achieve something like the file can only be downloaded by particular types of users, ie; Business or Consumer? I'm not sure what your goal is, but if it is simply to enable a file to be available for downloading, in general, use a plain old html link (<a>)

ryandoah
 
Thanks for taking the time to reply ryandoah. I don't know why I didn't just try the hyperlink, maybe it was because I'd confused myself by reading all sorts about FSO etc and then searching the web for info on file downloading using FSO but I didn't see anything that made it so obvious and didn't understand what the programmer in the javascript forum meant. So cheers for that it is so simple and I didn't think anyone was going to reply.

Sometimes the obvious things to try are too easy.
 
lol, We all know the feeling.

Keep familiar with the FSO stuff, though, it can be quite handy from time to time.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top