473,473 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Downloading files...

The help is not very informative here, but it says, that it is possible to
download files, by using the 'a' tag. What I am trying to do, is create a
link, that the user clicks, which will download a file from the server. This
works fine for most files, but for things like TXT and HTM, they open in the
browser window. I want the 'Save As' dialog box to appear, instead...

If I use;
Response.Write "<a href='http://mydomain/myfile.txt'>myfile</a>"
I get the contents of myfile.txt displayed in the browser window. If I use;
Response.Write "<a href='http://mydomain/myfile.mdb'>myfile</a>"
I get the 'save file as' dialog box appear. How do I force the 'save file
as' dialog box to appear for ALL files?

I tried using the 'FileSystemObject' and using the 'Copy' method of GetFile.
But this does not allow you to have a 'user defined' path to save the file
(which is pretty obvious, as this is the server side)... Is there another
function that I can use, or is there a property setting of the anchor tag,
that I need to set?
Jul 19 '05 #1
6 4149

"Ruskin Hardie" <Ru******@xtra.NOSPAM.co.nz> wrote in message
news:lR*****************@news.xtra.co.nz...
| The help is not very informative here, but it says, that it is
possible to
| download files, by using the 'a' tag. What I am trying to do,
is create a
| link, that the user clicks, which will download a file from the
server. This
| works fine for most files, but for things like TXT and HTM,
they open in the
| browser window. I want the 'Save As' dialog box to appear,
instead...
|
| If I use;
| Response.Write "<a
href='http://mydomain/myfile.txt'>myfile</a>"
| I get the contents of myfile.txt displayed in the browser
window. If I use;
| Response.Write "<a
href='http://mydomain/myfile.mdb'>myfile</a>"
| I get the 'save file as' dialog box appear. How do I force the
'save file
| as' dialog box to appear for ALL files?
|
| I tried using the 'FileSystemObject' and using the 'Copy'
method of GetFile.
| But this does not allow you to have a 'user defined' path to
save the file
| (which is pretty obvious, as this is the server side)... Is
there another
| function that I can use, or is there a property setting of the
anchor tag,
| that I need to set?
|

It's somewhat hard to control your visitor's browsers settings.
Most browsers are set to display .txt and .htm files. Depending
on your server, I believe it's possible to configure some servers
that would send the file different, but then I'm not sure if your
pages would appear (they're .htm probably). You may want to check
with your hosting provider.

One other way is to put the files into a .zip file. Not only will
this download properly, the file size may be greatly reduced.

hth
--
Chet
ng******@NOcharterSPAM.net (remove NO.....SPAM)
Jul 19 '05 #2
> The help is not very informative here, but it says, that it is possible
to download files, by using the 'a' tag. What I am trying to do, is
create a
link, that the user clicks, which will download a file from the server..
This works fine for most files, but for things like TXT and HTM, they
open in the browser window. I want the 'Save As' dialog box to appear,
instead...


the behaviour of the browser is triggered by the file's
content-disposition header. if you are, for example, streaming a txt file
to the user and want to force a download, you can even specify the file to
save it as by placing this line above all of the other code on the page:

Response.AddHeader "content-disposition","attachment; filename=fname.ext"

more information on this technique and how to use it statically can be
found here:
http://support.microsoft.com/default...NoWebContent=1
jenny
Jul 19 '05 #3

"jenny mabe" <ne**@rabidduck.com> wrote in message
news:opr3ym3qx8qafk40@localhost...
| > The help is not very informative here, but it says, that it
is possible
| > to download files, by using the 'a' tag. What I am trying to
do, is
| > create a
| > link, that the user clicks, which will download a file from
the server.
| > This works fine for most files, but for things like TXT and
HTM, they
| > open in the browser window. I want the 'Save As' dialog box
to appear,
| > instead...
|
| the behaviour of the browser is triggered by the file's
| content-disposition header. if you are, for example, streaming
a txt file
| to the user and want to force a download, you can even specify
the file to
| save it as by placing this line above all of the other code on
the page:
|
| Response.AddHeader "content-disposition","attachment;
filename=fname.ext"
|
| more information on this technique and how to use it statically
can be
| found here:
|
|http://support.microsoft.com/default...p://support.mi
crosoft.com:80/support/kb/articles/Q260/5/19.ASP&NoWebContent=1
|
|
| jenny

Jenny

When you do this dynamically, you would change fname.ext to the
file you wanted download, correct? And you'd place it as below:

<%@ Language=VBScript %>
<% Response.AddHeader "content-disposition","attachment;
filename=sample.htm"
%>
<!DOCTYPE ...>
<html>
<head>
</head>
<body>content of htm file to be downloaded
</body>
</html>

A few quick questions,

1) Could you include asp in the "sample.htm" file (above) that
would be parsed prior to being sent?

2) On the page you referenced, it says, "To apply the header
statically, right-click the document in the Internet Service
Manager...enter the content-disposition header there."

I'm learning, what's the Internet Service Manager. I "presume"
its on the server (IIS)?? I use PWS on Win98SE and haven't ran
across this. I liked the part about the bug in IE4! (ha)

3) On the page you referenced, it also says, "When Internet
Explorer receives the header..." Will this work with other
browsers? i.e., Mozilla, Netscape, Opera...etc.

Thanks for the info in your first reply.
--
Chet
ng******@NOcharterSPAM.net (remove NO.....SPAM)
Jul 19 '05 #4
On Wed, 25 Feb 2004 21:33:05 -0800, Chet <ng******@NOcharterSPAM.net>
wrote:
When you do this dynamically, you would change fname.ext to the
file you wanted download, correct? And you'd place it as below:

<%@ Language=VBScript %>
<% Response.AddHeader "content-disposition","attachment;
filename=sample.htm"
%>
yes, that is correct.
1) Could you include asp in the "sample.htm" file (above) that
would be parsed prior to being sent?
create the asp page to display just as in any other asp page the contents
you want the user to see when the file is opened -- any asp or html or
anything else you would normally display. you can really put anything here
-- plain text for a txt file, an html table for an excel file (excel will
automatically convert html tables), anything as long as the content-type
header and the file in the content-disposition header are set correctly
for the file.
2) On the page you referenced, it says, "To apply the header
statically, right-click the document in the Internet Service
Manager...enter the content-disposition header there."
I'm learning, what's the Internet Service Manager. I "presume"
its on the server (IIS)?? I use PWS on Win98SE and haven't ran
across this. I liked the part about the bug in IE4! (ha)
yes, that would be IIS. unfortunately, i dont have a 98 machine to check
for your operating system -- whatever application or control panel you use
to designate website properties, directories, etc.
3) On the page you referenced, it also says, "When Internet
Explorer receives the header..." Will this work with other
browsers? i.e., Mozilla, Netscape, Opera...etc.


yes, it should. some relevant info is here:
http://www.onjava.com/pub/a/onjava/e..._3/index3.html
jenny
Jul 19 '05 #5
Thanks Jenny, really appreciate the info.

--
Chet
ng******@NOcharterSPAM.net (remove NO.....SPAM)
Jul 19 '05 #6
<%
strFileName="force_download.asp" 'file to download

Response.Buffer = True
strFilePath=server.mappath(strFilename)
set fso=createobject("scripting.filesystemobject")
set f=fso.getfile(strfilepath)
strFileSize = f.size
set f=nothing: set fso=nothing
Const adTypeBinary = 1
Response.Clear
Set objStream = Server.CreateObject("ADODB.Stream")
objStream.Open
objStream.Type = adTypeBinary
objStream.LoadFromFile strFilePath
strFileType = "file/asp" ' change to the correct content type for your file
Response.AddHeader "Content-Disposition", "attachment; filename=" &
strFileName
Response.AddHeader "Content-Length", strFileSize
Response.Charset = "UTF-8"
Response.ContentType = strFileType
Response.BinaryWrite objStream.Read
Response.Flush
objStream.Close
Set objStream = Nothing
%>
"Ruskin Hardie" <Ru******@xtra.NOSPAM.co.nz> wrote in message
news:lR*****************@news.xtra.co.nz...
The help is not very informative here, but it says, that it is possible to
download files, by using the 'a' tag. What I am trying to do, is create a
link, that the user clicks, which will download a file from the server. This works fine for most files, but for things like TXT and HTM, they open in the browser window. I want the 'Save As' dialog box to appear, instead...

If I use;
Response.Write "<a href='http://mydomain/myfile.txt'>myfile</a>"
I get the contents of myfile.txt displayed in the browser window. If I use; Response.Write "<a href='http://mydomain/myfile.mdb'>myfile</a>"
I get the 'save file as' dialog box appear. How do I force the 'save file
as' dialog box to appear for ALL files?

I tried using the 'FileSystemObject' and using the 'Copy' method of GetFile. But this does not allow you to have a 'user defined' path to save the file
(which is pretty obvious, as this is the server side)... Is there another
function that I can use, or is there a property setting of the anchor tag,
that I need to set?

Jul 19 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Luke StClair | last post by:
Only marginally belonging in this newsgroup... but oh well. I've just started writing in python, and I want to make the files available on the web. So I did the standard <a...
0
by: sales | last post by:
If you are having difficulty downloading large files, please check out www.Downloads4Dialups.com. Mention this newsgroup in the "Special Instructions" window on the Shipping Form, and receive a...
2
by: Bala | last post by:
Hi I am trying to download the PDF files from my webserver using ASP.Net. All my files are stored at F Drive on webserver. Like this F:\Main Folder\Sub Folder\Files\File1.pdf I am...
1
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
3
by: just.starting | last post by:
Hi, My dot net client downloads files and checks for any new files time to time. The server is apache2.0.53 server. So what happens is that my file download thing works fine if I dont try to call...
0
by: just.starting | last post by:
I am having problem while downloading files from an apache server2.0.53 with php4.3.10.While downloading some files it generally stops after downloading some specific amount and then stops...
4
by: aldonnelley | last post by:
Hi there: a bit of a left-field question, I think. I'm writing a program that analyses image files downloaded with a basic crawler, and it's slow, mainly because I only want to analyse files...
3
by: xeroxero | last post by:
I would like to prevent people from downloading a .zip from a ASP.NET 2.0 web site, but still allow people to touch a .aspx page in the same directory. I also want to set things so if a user clicks...
1
by: =?Utf-8?B?U2FjaGluIENoYXZhbg==?= | last post by:
Hi, I need to download files from the FTP location. This FTP location is readonly n I dont hv access to delete files from this location once downloaded. The files to the ftp location keeps...
7
by: Ehsan | last post by:
I foundd this code in ASPN Python Cookbook for downloading files in python but when it finished downloading files the files became corrupted and didn't open, the files in internet havn't any...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.