Downloading a file to client

Ask a Question related to ASP.NET General, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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...
    5. 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"...
  3. #2

    Default 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...
    > 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...
    > > 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.
    >
    >
    >

    William F. Robertson, Jr. Guest

  4. #3

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139