Content-Disposition attatchment question

Discussion in 'ASP .Net' started by Martin, Jul 31, 2007.

  1. Martin

    Martin Guest

    I have a link in a page that allows the user to download a dynamically
    created XLS file. I add these headers and everything works correctly -
    as long as the .xls file is in the "home" folder.
    AddHeader("Content-Disposition", "attachment; filename=MyFile.xls")
    AddHeader("Content-type", "application/xls")

    But, I would like to create the file in a sub-folder and send it out
    from there. I've tried putting in a pathname like so:
    filename=\subfolder\MyFile.xls but I can't get anything to work (the
    response to the user is "File not found".

    How can I get this to work?
    Martin, Jul 31, 2007
    #1
    1. Advertising

  2. The name should be relative to your server application root.

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Martin" <> wrote in message
    news:...
    >I have a link in a page that allows the user to download a dynamically
    > created XLS file. I add these headers and everything works correctly -
    > as long as the .xls file is in the "home" folder.
    > AddHeader("Content-Disposition", "attachment; filename=MyFile.xls")
    > AddHeader("Content-type", "application/xls")
    >
    > But, I would like to create the file in a sub-folder and send it out
    > from there. I've tried putting in a pathname like so:
    > filename=\subfolder\MyFile.xls but I can't get anything to work (the
    > response to the user is "File not found".
    >
    > How can I get this to work?
    Eliyahu Goldin, Jul 31, 2007
    #2
    1. Advertising

  3. Martin

    Martin Guest

    On Tue, 31 Jul 2007 17:52:05 +0300, "Eliyahu Goldin"
    <> wrote:

    >The name should be relative to your server application root.


    That's what I'm doing. I created a sub-folder named XLSFiles in the
    server root. That's where I'm creating the xls files.

    Can you give me an example of the exact syntax to use?

    Is it filename=\XLSFiles\MyFile.xls
    Or filename=.\XLSFiles\MyFile.xls
    Or filename=..\XLSFiles\MyFile.xls
    Or filename=\XLSFiles/MyFile.xls
    Or ...

    I've tried everything I can think of - nothing works.
    Martin, Jul 31, 2007
    #3
  4. It should be server application root, off the application virtual directory.

    And the path will be

    XLSFiles/MyFile.xls

    --
    Eliyahu Goldin,
    Software Developer
    Microsoft MVP [ASP.NET]
    http://msmvps.com/blogs/egoldin
    http://usableasp.net


    "Martin" <> wrote in message
    news:...
    > On Tue, 31 Jul 2007 17:52:05 +0300, "Eliyahu Goldin"
    > <> wrote:
    >
    >>The name should be relative to your server application root.

    >
    > That's what I'm doing. I created a sub-folder named XLSFiles in the
    > server root. That's where I'm creating the xls files.
    >
    > Can you give me an example of the exact syntax to use?
    >
    > Is it filename=\XLSFiles\MyFile.xls
    > Or filename=.\XLSFiles\MyFile.xls
    > Or filename=..\XLSFiles\MyFile.xls
    > Or filename=\XLSFiles/MyFile.xls
    > Or ...
    >
    > I've tried everything I can think of - nothing works.
    >
    >
    Eliyahu Goldin, Jul 31, 2007
    #4
  5. Martin

    Patrice Guest

    IMO it could be unrelated. Content-disposition just suggests a name for the
    downloaded file (it doesn't even have to be an existing file).

    For now it's a bit unclear but it would make me rather think that the
    problem is in the code that streams the file to the browser. This is where
    the updated location should be taken into account.

    ---
    Patrice

    "Martin" <> a écrit dans le message de news:
    ...
    >I have a link in a page that allows the user to download a dynamically
    > created XLS file. I add these headers and everything works correctly -
    > as long as the .xls file is in the "home" folder.
    > AddHeader("Content-Disposition", "attachment; filename=MyFile.xls")
    > AddHeader("Content-type", "application/xls")
    >
    > But, I would like to create the file in a sub-folder and send it out
    > from there. I've tried putting in a pathname like so:
    > filename=\subfolder\MyFile.xls but I can't get anything to work (the
    > response to the user is "File not found".
    >
    > How can I get this to work?
    Patrice, Jul 31, 2007
    #5
  6. Martin

    Martin Guest

    I agree with what you're saying. Do you have any idea as to how I
    would get the server to use a different location? It seems to be able
    to find the created file only if I put it in the server's application
    root directory.

    I tried creating a virtual directory named XLSFiles but that made no
    difference.



    On Tue, 31 Jul 2007 17:41:52 +0200, "Patrice"
    <http://www.chez.com/scribe/> wrote:

    >IMO it could be unrelated. Content-disposition just suggests a name for the
    >downloaded file (it doesn't even have to be an existing file).
    >
    >For now it's a bit unclear but it would make me rather think that the
    >problem is in the code that streams the file to the browser. This is where
    >the updated location should be taken into account.
    >
    >---
    >Patrice
    >
    >"Martin" <> a écrit dans le message de news:
    >...
    >>I have a link in a page that allows the user to download a dynamically
    >> created XLS file. I add these headers and everything works correctly -
    >> as long as the .xls file is in the "home" folder.
    >> AddHeader("Content-Disposition", "attachment; filename=MyFile.xls")
    >> AddHeader("Content-type", "application/xls")
    >>
    >> But, I would like to create the file in a sub-folder and send it out
    >> from there. I've tried putting in a pathname like so:
    >> filename=\subfolder\MyFile.xls but I can't get anything to work (the
    >> response to the user is "File not found".
    >>
    >> How can I get this to work?

    >
    Martin, Aug 2, 2007
    #6
  7. Martin

    Patrice Guest

    If this is a virtual directory you'll have to user Server.MapPath to
    transform this location into a physical server side directory. Using the
    full absolute path of the file you can then use Response.WriteFile to stream
    the file from this location .

    For now you could just stream a sample text file directly to the browser
    wihtout the content disposition header so that you can see whatever happens
    includiong a possible error. Also try first to write down just the file
    location so that you can check the absolute path is correct...

    For now I would say that the file location is not correctly created
    resulting in not finding the file...

    --
    Patrice

    "Martin" <> a écrit dans le message de news:
    ...
    >I agree with what you're saying. Do you have any idea as to how I
    > would get the server to use a different location? It seems to be able
    > to find the created file only if I put it in the server's application
    > root directory.
    >
    > I tried creating a virtual directory named XLSFiles but that made no
    > difference.
    >
    >
    >
    > On Tue, 31 Jul 2007 17:41:52 +0200, "Patrice"
    > <http://www.chez.com/scribe/> wrote:
    >
    >>IMO it could be unrelated. Content-disposition just suggests a name for
    >>the
    >>downloaded file (it doesn't even have to be an existing file).
    >>
    >>For now it's a bit unclear but it would make me rather think that the
    >>problem is in the code that streams the file to the browser. This is where
    >>the updated location should be taken into account.
    >>
    >>---
    >>Patrice
    >>
    >>"Martin" <> a écrit dans le message de news:
    >>...
    >>>I have a link in a page that allows the user to download a dynamically
    >>> created XLS file. I add these headers and everything works correctly -
    >>> as long as the .xls file is in the "home" folder.
    >>> AddHeader("Content-Disposition", "attachment; filename=MyFile.xls")
    >>> AddHeader("Content-type", "application/xls")
    >>>
    >>> But, I would like to create the file in a sub-folder and send it out
    >>> from there. I've tried putting in a pathname like so:
    >>> filename=\subfolder\MyFile.xls but I can't get anything to work (the
    >>> response to the user is "File not found".
    >>>
    >>> How can I get this to work?

    >>

    >
    Patrice, Aug 3, 2007
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ramjee Tanguturi

    Content Disposition Problem with IE

    Ramjee Tanguturi, Nov 17, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    1,543
    Ramjee Tanguturi
    Nov 17, 2003
  2. =?Utf-8?B?TmlrbGFz?=

    Use DIME/attatchment to download an application

    =?Utf-8?B?TmlrbGFz?=, Aug 10, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    825
    =?Utf-8?B?TmlrbGFz?=
    Aug 10, 2004
  3. Alex Nitulescu

    Content-disposition question

    Alex Nitulescu, Mar 4, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,385
    Alex Nitulescu
    Mar 4, 2005
  4. UnglueD
    Replies:
    0
    Views:
    369
    UnglueD
    Oct 4, 2006
  5. Niklas

    Use DIME/attatchment to download an application

    Niklas, Aug 10, 2004, in forum: ASP .Net Web Services
    Replies:
    0
    Views:
    95
    Niklas
    Aug 10, 2004
Loading...

Share This Page