Save or Open

Discussion in 'ASP .Net' started by John, Jun 25, 2003.

  1. John

    John Guest

    Hi,

    I generate a report in a comma delimited file and give it
    a name like MyReport.csv . I then set a Hyperlink
    control to point tp the file

    HyperLink1.text = "Download"
    Hyperlink1.NavigateUrl = "MyReport.csv"

    When the user clicks the HyperLink I would always like to
    see the dialog come up that asks if you want to 'Open' the
    file or 'Save' the file to disk.

    I get mixed results. If the client has Excel installed
    then this dialog does not come up and IE pops the file
    into a spread sheet. If Excel is not installed then IE
    pops the file up in a text window (same thing happens if I
    delete the csv from the folder options).

    If I change the file extension to something strange
    like .xyz123 then it always comes up with the dialog but
    I want the user to have the option to save the file as
    csv.

    Anyway, is there some way to force this to always come up
    with the Open or Save dialog?

    Tks,
    JOhn
     
    John, Jun 25, 2003
    #1
    1. Advertising

  2. Not that i know of. Users can force the dialog manually by right clicking /
    Save Target As. Either that or just zip the file.
    -Trevor


    "John" <> wrote in message
    news:010901c33b2c$46cc9bc0$...
    > Hi,
    >
    > I generate a report in a comma delimited file and give it
    > a name like MyReport.csv . I then set a Hyperlink
    > control to point tp the file
    >
    > HyperLink1.text = "Download"
    > Hyperlink1.NavigateUrl = "MyReport.csv"
    >
    > When the user clicks the HyperLink I would always like to
    > see the dialog come up that asks if you want to 'Open' the
    > file or 'Save' the file to disk.
    >
    > I get mixed results. If the client has Excel installed
    > then this dialog does not come up and IE pops the file
    > into a spread sheet. If Excel is not installed then IE
    > pops the file up in a text window (same thing happens if I
    > delete the csv from the folder options).
    >
    > If I change the file extension to something strange
    > like .xyz123 then it always comes up with the dialog but
    > I want the user to have the option to save the file as
    > csv.
    >
    > Anyway, is there some way to force this to always come up
    > with the Open or Save dialog?
    >
    > Tks,
    > JOhn
     
    Trevor Hartman, Jun 25, 2003
    #2
    1. Advertising

  3. Try creating an ASPX page that opens and reads the file, and then sets the
    Response.ContentType property to "application/octet-stream" and then
    Response.BinaryWrite()s the file to the output stream. Then you can link to
    this file, and you should get the desired effect.

    HTH,

    Kevin Spencer
    Microsoft FrontPage MVP
    Internet Developer
    http://www.takempis.com
    Big things are made up of
    lots of Little things.

    "John" <> wrote in message
    news:010901c33b2c$46cc9bc0$...
    > Hi,
    >
    > I generate a report in a comma delimited file and give it
    > a name like MyReport.csv . I then set a Hyperlink
    > control to point tp the file
    >
    > HyperLink1.text = "Download"
    > Hyperlink1.NavigateUrl = "MyReport.csv"
    >
    > When the user clicks the HyperLink I would always like to
    > see the dialog come up that asks if you want to 'Open' the
    > file or 'Save' the file to disk.
    >
    > I get mixed results. If the client has Excel installed
    > then this dialog does not come up and IE pops the file
    > into a spread sheet. If Excel is not installed then IE
    > pops the file up in a text window (same thing happens if I
    > delete the csv from the folder options).
    >
    > If I change the file extension to something strange
    > like .xyz123 then it always comes up with the dialog but
    > I want the user to have the option to save the file as
    > csv.
    >
    > Anyway, is there some way to force this to always come up
    > with the Open or Save dialog?
    >
    > Tks,
    > JOhn
     
    Kevin Spencer, Jun 25, 2003
    #3
  4. John

    john Guest

    Thanks, this seems to work. One small problem, when you
    clict 'Open' it repeats the dialog and you need to click
    Open a second time. But, much better than before.

    >-----Original Message-----
    >It is a tricky problem, most browsers try to do whatever

    they can depending
    >on the type of file.
    >However, it is possible to override the headers of the

    output to convince
    >the browser that it should try and do something else with

    it.
    >
    >Instead of just a hyperlink url, generate a control

    (button / imagebutton
    >etc) with an event / postback
    >Then within the server side code (OnClick) use the

    following with the
    >Response object.
    >
    >Response.AppendHeader( "content-disposition", "attachment;
    >filename=MyReport.csv");
    > Response.WriteFile(Server.MapPath

    ("MyReport.csv"));
    > Response.End();
    >
    >Regards,
    >Robin
    >
    >"John" <> wrote in message
    >news:010901c33b2c$46cc9bc0$...
    >> Hi,
    >>
    >> I generate a report in a comma delimited file and give

    it
    >> a name like MyReport.csv . I then set a Hyperlink
    >> control to point tp the file
    >>
    >> HyperLink1.text = "Download"
    >> Hyperlink1.NavigateUrl = "MyReport.csv"
    >>
    >> When the user clicks the HyperLink I would always like

    to
    >> see the dialog come up that asks if you want to 'Open'

    the
    >> file or 'Save' the file to disk.
    >>
    >> I get mixed results. If the client has Excel installed
    >> then this dialog does not come up and IE pops the file
    >> into a spread sheet. If Excel is not installed then IE
    >> pops the file up in a text window (same thing happens

    if I
    >> delete the csv from the folder options).
    >>
    >> If I change the file extension to something strange
    >> like .xyz123 then it always comes up with the dialog

    but
    >> I want the user to have the option to save the file as
    >> csv.
    >>
    >> Anyway, is there some way to force this to always come

    up
    >> with the Open or Save dialog?
    >>
    >> Tks,
    >> JOhn

    >
    >
    >.
    >
     
    john, Jun 25, 2003
    #4
  5. John

    Robin Day Guest

    Sorry about blank reply!! Ack, itchy fingers!

    Strange, check that there are no other Response Redirects or Url links as
    part of this control. Also, maybe try clearing the Response object before
    adding the new header and writing the file.

    In general whenever I find I need to force the use to do a save as (as
    below) I usually provide two buttons, one for save, one for open. The save
    forces the dialog and the open just does a response.redirect. That way they
    never have the need to click the Save button and then try and open it.

    "john" <> wrote in message
    news:0c3a01c33b55$e112caf0$...
    > Thanks, this seems to work. One small problem, when you
    > clict 'Open' it repeats the dialog and you need to click
    > Open a second time. But, much better than before.
    >
    > >-----Original Message-----
    > >It is a tricky problem, most browsers try to do whatever

    > they can depending
    > >on the type of file.
    > >However, it is possible to override the headers of the

    > output to convince
    > >the browser that it should try and do something else with

    > it.
    > >
    > >Instead of just a hyperlink url, generate a control

    > (button / imagebutton
    > >etc) with an event / postback
    > >Then within the server side code (OnClick) use the

    > following with the
    > >Response object.
    > >
    > >Response.AppendHeader( "content-disposition", "attachment;
    > >filename=MyReport.csv");
    > > Response.WriteFile(Server.MapPath

    > ("MyReport.csv"));
    > > Response.End();
    > >
    > >Regards,
    > >Robin
    > >
    > >"John" <> wrote in message
    > >news:010901c33b2c$46cc9bc0$...
    > >> Hi,
    > >>
    > >> I generate a report in a comma delimited file and give

    > it
    > >> a name like MyReport.csv . I then set a Hyperlink
    > >> control to point tp the file
    > >>
    > >> HyperLink1.text = "Download"
    > >> Hyperlink1.NavigateUrl = "MyReport.csv"
    > >>
    > >> When the user clicks the HyperLink I would always like

    > to
    > >> see the dialog come up that asks if you want to 'Open'

    > the
    > >> file or 'Save' the file to disk.
    > >>
    > >> I get mixed results. If the client has Excel installed
    > >> then this dialog does not come up and IE pops the file
    > >> into a spread sheet. If Excel is not installed then IE
    > >> pops the file up in a text window (same thing happens

    > if I
    > >> delete the csv from the folder options).
    > >>
    > >> If I change the file extension to something strange
    > >> like .xyz123 then it always comes up with the dialog

    > but
    > >> I want the user to have the option to save the file as
    > >> csv.
    > >>
    > >> Anyway, is there some way to force this to always come

    > up
    > >> with the Open or Save dialog?
    > >>
    > >> Tks,
    > >> JOhn

    > >
    > >
    > >.
    > >
     
    Robin Day, Jun 26, 2003
    #5
    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. user
    Replies:
    1
    Views:
    795
    Bruce Barker
    Apr 4, 2005
  2. BusyBoy
    Replies:
    2
    Views:
    631
    =?Utf-8?B?TGVvbiBNYXluZQ==?=
    Oct 31, 2006
  3. tiewknvc9
    Replies:
    12
    Views:
    1,366
    Chris Uppal
    Feb 19, 2007
  4. Iain
    Replies:
    1
    Views:
    436
    Alexey Smirnov
    Apr 9, 2007
  5. eddie wang
    Replies:
    0
    Views:
    435
    eddie wang
    Oct 3, 2003
Loading...

Share This Page