File download

A

Andrew Chalk

How do I do file download from an ASP.NET v1.x page?

Specifically if I have a link e.g. "Download" in a datagrid what code will
cause the file download dialog to appear to the user?

Many thanks.
 
R

Rob Meade

...
How do I do file download from an ASP.NET v1.x page?

Specifically if I have a link e.g. "Download" in a datagrid what code will
cause the file download dialog to appear to the user?

<a href="my_file_to_download.zip" title="Download me!">Download</a>

Rob
 
A

Andrew Chalk

What are the advantages and disadvantages of that versus the WebClient
class?

Thanks,

Andrew
 
P

Patrice

The webclient class allows to do this programmtically from an application.

Unless you do this from a client side application, it would be useless (that
is it would run server side so you would get the file on the server anyway).

--
 
A

Andrew Chalk

So I can't use WebClient on an ASP.NET page to download a file to a browser
client?

Thanks.
 
J

Joerg Jooss

Andrew said:
So I can't use WebClient on an ASP.NET page to download a file to a
browser client?

No, because it's a *client*. On the server-side, you can either provide
"direct" download capability (i.e. a hyperlink to URL that represents a
physical file) or "programmed" downloads (i.e. a hyperlink to a ASP.NET
page or a HttpHandler, which performs the download).

cheers,
 
A

Andrew Chalk

I need the latter. I.e. an HttpHandler. Can you refer me to an example of
this?

Many thanks.
 
A

Andrew Chalk

I do have one problem however: If I am downloading a file named
"AJC2.00.040.000001.wav"
the download dialog displays it as:

"AJC2[1].00.040.000001.wav"

AJC2, incidentally, is the server name.

Does anyone have any idea how to stop this?

Many thanks.

Andrew Chalk said:
Thanks, although that is really too general for this problem. A more
general reference is:

http://www.asp101.com/samples/download_sample_aspx.asp

- Andrew
 
A

Andrew Chalk

FYI: The code I use is:
Response.Clear();

Response.ContentType = "application/x-download";

Response.AddHeader("Content-Disposition", "attachment; filename=" +
sFileName);



Andrew Chalk said:
I do have one problem however: If I am downloading a file named
"AJC2.00.040.000001.wav"
the download dialog displays it as:

"AJC2[1].00.040.000001.wav"

AJC2, incidentally, is the server name.

Does anyone have any idea how to stop this?

Many thanks.
 
R

Rob Meade

...
FYI: The code I use is:
Response.Clear();

Response.ContentType = "application/x-download";

Response.AddHeader("Content-Disposition", "attachment; filename=" +
sFileName);

Did that get rid of the square brackets?

Regards

Rob
 
A

Andrew Chalk

No, that is the code under which they are produced. This is a very odd
problem.

- A
 
R

Rob Meade

...
No, that is the code under which they are produced. This is a very odd
problem.

As I suspected :eek:)

I've encountered this problem myself with a document management application
I wrote, I believe it happens for 2 reasons (1 more than the other I think)
....

1. If the file is already within the clients temporary internet files as a
cached version you'll get a [n] on the end,with the n referring to a numeric
value indicating another duplicate of the same file.

2. When you have more than one . (dot) in the file name it is then unable to
determine the file extension thus it adds some square brackets.

We completely removed this issue in our scenario by removing addition .'s
(dots) from the file names, you could perhaps replace them with underscores
or hyphens if you really need something.

It might not be what you want, but try it - you'll probably find you no
longer get the [ ] once you remove the additions dots..

HTH

Rob
 
A

Andrew Chalk

Thanks, Rob. That's very helpful.

Regards,

Andrew
Rob Meade said:
...
No, that is the code under which they are produced. This is a very odd
problem.

As I suspected :eek:)

I've encountered this problem myself with a document management
application I wrote, I believe it happens for 2 reasons (1 more than the
other I think) ...

1. If the file is already within the clients temporary internet files as a
cached version you'll get a [n] on the end,with the n referring to a
numeric value indicating another duplicate of the same file.

2. When you have more than one . (dot) in the file name it is then unable
to determine the file extension thus it adds some square brackets.

We completely removed this issue in our scenario by removing addition .'s
(dots) from the file names, you could perhaps replace them with
underscores or hyphens if you really need something.

It might not be what you want, but try it - you'll probably find you no
longer get the [ ] once you remove the additions dots..

HTH

Rob
 
A

Andrew Chalk

FYI: I can't delete the periods, so I think my users are going to live with
this quirk.

- A
 
R

Rob Meade

...
FYI: I can't delete the periods, so I think my users are going to live
with this quirk.

Hi Andrew,

Is this because of a technical reason or because of a "policy" within your
organisation (ie,someone saying - no they must have those periods there) ?

Regards

Rob
 
A

Andrew Chalk

policy-wolicy..
Rob Meade said:
...


Hi Andrew,

Is this because of a technical reason or because of a "policy" within your
organisation (ie,someone saying - no they must have those periods there) ?

Regards

Rob
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,062
Latest member
OrderKetozenseACV

Latest Threads

Top