PC Review


Reply
Thread Tools Rate Thread

Downloading a file to client

 
 
Ian Gordon
Guest
Posts: n/a
 
      30th Jul 2003
Hi,

I have 2 problems when downloading a file from my ASP.net app to the client
PC. At the moment I'm doing it with the following code:

Response.ContentType = "application/octet-stream"

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

Response.WriteFile(strFileToDownload)



The problems are:
1. How can I set the name of document to be downloaded? At the moment, the
name of file is by default set to be the name of the web form that it comes
from, which is far from ideal. to be able to call it, for example,
myFile.doc.
2. How can I try and force the save to be in a specific directory, or even
to default to the Windows temp directory, or to My Documents? At the moment,
the default target directory seems quite different on different machines.

All help very much appreciated.

Ian
(E-Mail Removed)


 
Reply With Quote
 
 
 
 
William F. Robertson, Jr.
Guest
Posts: n/a
 
      30th Jul 2003
Also you might want to look at putting a marker such as " or ' around the
file name. If there are spaces in the filename, I don't know exactly that
would do, but I am sure it isn't going to be desired behavior.

Also it might be a setting on the broswer you are using. I had a web app
for the division I am in that worked fine, except when the site was used
outside the development group. The firm standard did not allow the filename
to be passed to the download dialog.

bill

"Peter O'Reilly" <(E-Mail Removed)!N!O!.S!P!AM!> wrote in message
news:(E-Mail Removed)...
> see in line comments...
>
> --
> Peter O'Reilly
> "Ian Gordon" <(E-Mail Removed)> wrote in message
> news:dyWVa.24$_(E-Mail Removed)...
> > Hi,
> >
> > I have 2 problems when downloading a file from my ASP.net app to the

> client
> > PC. At the moment I'm doing it with the following code:
> >
> > Response.ContentType = "application/octet-stream"
> >
> > Response.AddHeader("Content-Disposition", "attachment; filename=" +
> > strFileToDownload)
> >
> > Response.WriteFile(strFileToDownload)
> >

>
> > The problems are:
> > 1. How can I set the name of document to be downloaded? At the moment,

the
> > name of file is by default set to be the name of the web form that it

> comes
> > from, which is far from ideal. to be able to call it, for example,
> > myFile.doc.

>
> Code looks fine. Adding the Content-Disposition HTTP Response header is

the
> solution. It could very well be a bug with that browser version. Have you
> tried requesting this file with a different browser?
>
> Alternatively, if in your example, myFile.doc is truly a MS Word document,
> have you tried changing the content type to more closely match the type of
> file, i.e. application/ms-word? That may help.
>
>
> > 2. How can I try and force the save to be in a specific directory, or

even
> > to default to the Windows temp directory, or to My Documents? At the

> moment,
> > the default target directory seems quite different on different

machines.
> >

> Sorry, no dice. It's this way due to security considerations. One

solution
> would be to create your own (perhaps 'trusted') ActiveX downloader

control,
> but that would be quite a bit more work to achieve such result.
>
>
>



 
Reply With Quote
 
 
 
 
Bill Priess
Guest
Posts: n/a
 
      30th Jul 2003
Hi Ian,

The fix is in this line:
Response.AddHeader("Content-Disposition", "attachment; filename=" +
System.IO.Path.GetFileName(strFileToDownload))

The Content-Disposition header requires only the file name, not the entire
path. When given the entire path, it negates and the browser will not set a
name for the file download dialog.

Also, you should call Response.Clear() before you add your headers just to
make sure that there are no other headers being sent down to the browser.


As for the second part of your question, no. This is a serious breach of
security.

HTH,

Bill P.

On Wed, 30 Jul 2003 22:15:55 +0100, Ian Gordon <(E-Mail Removed)> wrote:

> Hi,
>
> I have 2 problems when downloading a file from my ASP.net app to the
> client
> PC. At the moment I'm doing it with the following code:
>
> Response.ContentType = "application/octet-stream"
>
> Response.AddHeader("Content-Disposition", "attachment; filename=" +
> strFileToDownload)
>
> Response.WriteFile(strFileToDownload)
>
>
>
> The problems are:
> 1. How can I set the name of document to be downloaded? At the moment,
> the
> name of file is by default set to be the name of the web form that it
> comes
> from, which is far from ideal. to be able to call it, for example,
> myFile.doc.
> 2. How can I try and force the save to be in a specific directory, or
> even
> to default to the Windows temp directory, or to My Documents? At the
> moment,
> the default target directory seems quite different on different machines.
>
> All help very much appreciated.
>
> Ian
> (E-Mail Removed)
>
>
>




--
Using M2, Opera's revolutionary e-mail client: http://www.opera.com/m2/
 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
"EITHER THERE IS NO DEFAULT MAIL CLIENT OR THE CURRENT MAIL CLIENT CANNOT FULFILL THE MESSAGING REQUEST. PLEASE RUN MICROSOFT OUTLOOK AND SET IT AS THE DEFAULT MAIL CLIENT" Jon D. Schoenherz Microsoft Outlook Discussion 7 21st Mar 2009 06:43 AM
Downloading file to client Cathryn Johns Microsoft ASP .NET 3 2nd Nov 2005 01:24 PM
smart client .config file downloading to desktop =?Utf-8?B?amQ=?= Microsoft Dot NET Framework Forms 0 18th Aug 2005 05:51 PM
Downloading/opening file in client application window Rob Nicholson Microsoft ASP .NET 3 13th May 2005 03:26 AM
Client file downloading........ RC Microsoft ASP .NET 3 19th Jan 2005 10:33 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:06 AM.