Pushing a file to the user..

Discussion in 'ASP .Net' started by =?Utf-8?B?UmF2aSBK?=, Mar 2, 2005.

  1. Hello,
    I need to write an asp.net page that pushes a files to the user for download.
    The code I wrote works just fine, in that it sends a file to the user. But
    the HTML controls on the page are not updated..

    private void Button1_Click(object sender, System.EventArgs e)
    {
    //part 1
    TextBox3.Text = TextBox1.Text + " " + TextBox2.Text;
    TextBox1.Visible = TextBox2.Visible = TextBox3.Visible = false;
    TextBox1.Visible = TextBox2.Visible = TextBox3.Visible = true;
    Label1.Text = "Thank you for choosing this program.";

    //part 2
    System.IO.FileInfo info = new
    System.IO.FileInfo(System.Web.HttpContext.Current.Server.MapPath(".") + "\\"
    + "txt.txt");
    HttpContext.Current.Response.ClearHeaders();
    HttpContext.Current.Response.ClearContent();
    HttpContext.Current.Response.ContentType = "";
    HttpContext.Current.Response.AppendHeader("Content-Disposition:","
    attachment; filename=txt.txt");
    HttpContext.Current.Response.AppendHeader("Contect-Length", "100");
    HttpContext.Current.Response.Charset="UTF-8";
    HttpContext.Current.Response.WriteFile("txt.txt");
    HttpContext.Current.Response.Flush();
    HttpContext.Current.Response.Close();
    }
    The second part of the code above, the Response object sends the file down
    to the user, but the first part of code does not work. Is there a way to get
    both to work?

    Thanks in advance,
    =?Utf-8?B?UmF2aSBK?=, Mar 2, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?UmF2aSBK?=

    qwerty Guest

    Try switch part 1 and part 2 around


    On Tue, 1 Mar 2005 19:53:02 -0800, Ravi J
    <> wrote:

    >Hello,
    >I need to write an asp.net page that pushes a files to the user for download.
    >The code I wrote works just fine, in that it sends a file to the user. But
    >the HTML controls on the page are not updated..
    >
    >private void Button1_Click(object sender, System.EventArgs e)
    >{
    >//part 1
    >TextBox3.Text = TextBox1.Text + " " + TextBox2.Text;
    >TextBox1.Visible = TextBox2.Visible = TextBox3.Visible = false;
    >TextBox1.Visible = TextBox2.Visible = TextBox3.Visible = true;
    >Label1.Text = "Thank you for choosing this program.";
    >
    >//part 2
    >System.IO.FileInfo info = new
    >System.IO.FileInfo(System.Web.HttpContext.Current.Server.MapPath(".") + "\\"
    >+ "txt.txt");
    >HttpContext.Current.Response.ClearHeaders();
    >HttpContext.Current.Response.ClearContent();
    >HttpContext.Current.Response.ContentType = "";
    >HttpContext.Current.Response.AppendHeader("Content-Disposition:","
    >attachment; filename=txt.txt");
    >HttpContext.Current.Response.AppendHeader("Contect-Length", "100");
    >HttpContext.Current.Response.Charset="UTF-8";
    >HttpContext.Current.Response.WriteFile("txt.txt");
    >HttpContext.Current.Response.Flush();
    >HttpContext.Current.Response.Close();
    >}
    >The second part of the code above, the Response object sends the file down
    >to the user, but the first part of code does not work. Is there a way to get
    >both to work?
    >
    >Thanks in advance,
    qwerty, Mar 2, 2005
    #2
    1. Advertising

  3. There is no way for this to happen. A webrequest can only consist of one
    type. Either an image, excel file, or a webpage. part 1 is setting up the
    controls with certain values. Then you are clearing the response and
    sending the content type "", which I believe trusts the user's machine to
    decide what it is. (text file)

    The page changes you made in part one are never rendered to the browser.
    Also you probably should use Response.End() at the end of the direct file
    sending.

    IOW what you want to do is not possible with Html. My suggestion, if you
    want to do this, is to send part 1 back to the user, have some script that
    immediately submits the page, and that postback, you send the information in
    part 2. It involves an extra request, but many sites use this
    functionality.

    HTH,

    bill


    "Ravi J" <> wrote in message
    news:...
    > Hello,
    > I need to write an asp.net page that pushes a files to the user for

    download.
    > The code I wrote works just fine, in that it sends a file to the user. But
    > the HTML controls on the page are not updated..
    >
    > private void Button1_Click(object sender, System.EventArgs e)
    > {
    > //part 1
    > TextBox3.Text = TextBox1.Text + " " + TextBox2.Text;
    > TextBox1.Visible = TextBox2.Visible = TextBox3.Visible = false;
    > TextBox1.Visible = TextBox2.Visible = TextBox3.Visible = true;
    > Label1.Text = "Thank you for choosing this program.";
    >
    > //part 2
    > System.IO.FileInfo info = new
    > System.IO.FileInfo(System.Web.HttpContext.Current.Server.MapPath(".") +

    "\\"
    > + "txt.txt");
    > HttpContext.Current.Response.ClearHeaders();
    > HttpContext.Current.Response.ClearContent();
    > HttpContext.Current.Response.ContentType = "";
    > HttpContext.Current.Response.AppendHeader("Content-Disposition:","
    > attachment; filename=txt.txt");
    > HttpContext.Current.Response.AppendHeader("Contect-Length", "100");
    > HttpContext.Current.Response.Charset="UTF-8";
    > HttpContext.Current.Response.WriteFile("txt.txt");
    > HttpContext.Current.Response.Flush();
    > HttpContext.Current.Response.Close();
    > }
    > The second part of the code above, the Response object sends the file down
    > to the user, but the first part of code does not work. Is there a way to

    get
    > both to work?
    >
    > Thanks in advance,
    >
    William F. Robertson, Jr., Mar 2, 2005
    #3
  4. Thanks Bill for the response,
    I tried to shuffle part one and part two of the code, but it did not work.
    Is it possible to use javascript to do this?
    What other possible avanues exist for this problem?
    Once the user clicks a button, I would like the controls refreshed, and file
    sent to the user.
    What other workaround methods exist?

    Thanks in advance, for any hint or clue
    -Ravi
    =?Utf-8?B?UmF2aSBK?=, Mar 3, 2005
    #4
  5. Shuffling the parts on the page will not work. Either you can send the
    file, or an updated UI, but only one at a time.

    You will have to write out the updated UI in the first postback. The
    updated UI will have to write out some javascript code that will postback,
    immediately, and on this second postback, you can send the file to them.

    bill


    "Ravi J" <> wrote in message
    news:...
    > Thanks Bill for the response,
    > I tried to shuffle part one and part two of the code, but it did not work.
    > Is it possible to use javascript to do this?
    > What other possible avanues exist for this problem?
    > Once the user clicks a button, I would like the controls refreshed, and

    file
    > sent to the user.
    > What other workaround methods exist?
    >
    > Thanks in advance, for any hint or clue
    > -Ravi
    William F. Robertson, Jr., Mar 3, 2005
    #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. pxlpluker

    Pushing file name to browser

    pxlpluker, Mar 5, 2004, in forum: Python
    Replies:
    0
    Views:
    259
    pxlpluker
    Mar 5, 2004
  2. pxlpluker

    Pushing file name to browser

    pxlpluker, Mar 6, 2004, in forum: Python
    Replies:
    1
    Views:
    259
    Irmen de Jong
    Mar 6, 2004
  3. Hakan Nilsson

    Re: Pushing file name to browser

    Hakan Nilsson, Mar 7, 2004, in forum: Python
    Replies:
    2
    Views:
    247
    Irmen de Jong
    Mar 7, 2004
  4. graham.reeds
    Replies:
    9
    Views:
    1,101
    Pavel Lepin
    Feb 4, 2008
  5. Bertrand

    Using response.addheader for pushing file

    Bertrand, Nov 11, 2003, in forum: ASP General
    Replies:
    0
    Views:
    112
    Bertrand
    Nov 11, 2003
Loading...

Share This Page