Ask a Question related to ASP.NET General, Design and Development.
-
Ian Gordon #1
Downloading a file to client
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
[email]ian@xwebservices.net[/email]
Ian Gordon Guest
-
Smart Client Downloading -Sattelite Assembiles
Hi I am working with Smart Client.I am having a windows application which needs to works with Multiple Languages so i am using Sattilitie... -
Downloading file
i want to click on a link which then displays a file on the cd in word, how can i make this file able to be downloaded on the users computer? i... -
Downloading file(s) from CD
How can I make a button which start a downloading of file or more from the CD the presentation is running from, into the local hard disk in a... -
Downloading a file from a CD
Hi, Im using Director MX. On my CD, I want people to be able to click on an option that starts to download a video from my CD to the users... -
Downloading files from the server to the client browser
I want to download files, images, Word .docs, .pdfs, from the server to the browser. The user clicks on a link, gets the usual "File Download"... -
William F. Robertson, Jr. #2
Re: Downloading a file to client
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" <Peter_OReilly@timeinc.com!N!O!.S!P!AM!> wrote in message
news:eU6jEOuVDHA.2052@TK2MSFTNGP10.phx.gbl...the> see in line comments...
>
> --
> Peter O'Reilly
> "Ian Gordon" <xis@dircon.co.uk> wrote in message
> news:dyWVa.24$_M1.4533@news.dircon.co.uk...> client> > Hi,
> >
> > I have 2 problems when downloading a file from my ASP.net app to the>> > 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> comes> > name of file is by default set to be the name of the web form that it>> > 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 iseven> 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, ormachines.> moment,> > to default to the Windows temp directory, or to My Documents? At the> > the default target directory seems quite different on differentsolution> Sorry, no dice. It's this way due to security considerations. One> >control,> would be to create your own (perhaps 'trusted') ActiveX downloader> but that would be quite a bit more work to achieve such result.
>
>
>
William F. Robertson, Jr. Guest
-
Bill Priess #3
Re: Downloading a file to client
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 <xis@dircon.co.uk> 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
> [email]ian@xwebservices.net[/email]
>
>
>
--
Using M2, Opera's revolutionary e-mail client: [url]http://www.opera.com/m2/[/url]
Bill Priess Guest



Reply With Quote

