q; what is wrong with this code?

Discussion in 'ASP .Net' started by =?Utf-8?B?SklNLkgu?=, Sep 24, 2006.

  1. private void DownloadFile(string fName)
    {
    string msg="download done";

    /*
    System.IO.fInfo fInfo = new System.IO.fInfo(fName);
    Response.Clear();
    Response.AddHeader("Content-Disposition", "attachment; filename=" +
    fInfo.Name);
    Response.AddHeader("Content-Length", fInfo.Length.ToString());
    Response.ContentType = "application/octet-stream";
    Response.WriteFile(fInfo.FullName);
    */

    this.myLabel.ForeColor=System.Drawing.Color.Red;
    this.myLabel.Text=msg;
    }

    When I remove commented section, this method does not show the message in
    myLabel on my page, where is the problem?
     
    =?Utf-8?B?SklNLkgu?=, Sep 24, 2006
    #1
    1. Advertising

  2. The problem is that you're not sending an HTML document to the client. You
    are sending a binary file.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Software Composer
    http://unclechutney.blogspot.com

    A watched clock never boils.

    "JIM.H." <> wrote in message
    news:...
    > private void DownloadFile(string fName)
    > {
    > string msg="download done";
    >
    > /*
    > System.IO.fInfo fInfo = new System.IO.fInfo(fName);
    > Response.Clear();
    > Response.AddHeader("Content-Disposition", "attachment; filename=" +
    > fInfo.Name);
    > Response.AddHeader("Content-Length", fInfo.Length.ToString());
    > Response.ContentType = "application/octet-stream";
    > Response.WriteFile(fInfo.FullName);
    > */
    >
    > this.myLabel.ForeColor=System.Drawing.Color.Red;
    > this.myLabel.Text=msg;
    > }
    >
    > When I remove commented section, this method does not show the message in
    > myLabel on my page, where is the problem?
    >
    >
     
    Kevin Spencer, Sep 24, 2006
    #2
    1. Advertising

  3. Thanks Kevin, I am trying to make sure I am getting open/save dialog box, any
    solution for me?

    "Kevin Spencer" wrote:

    > The problem is that you're not sending an HTML document to the client. You
    > are sending a binary file.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > Software Composer
    > http://unclechutney.blogspot.com
    >
    > A watched clock never boils.
    >
    > "JIM.H." <> wrote in message
    > news:...
    > > private void DownloadFile(string fName)
    > > {
    > > string msg="download done";
    > >
    > > /*
    > > System.IO.fInfo fInfo = new System.IO.fInfo(fName);
    > > Response.Clear();
    > > Response.AddHeader("Content-Disposition", "attachment; filename=" +
    > > fInfo.Name);
    > > Response.AddHeader("Content-Length", fInfo.Length.ToString());
    > > Response.ContentType = "application/octet-stream";
    > > Response.WriteFile(fInfo.FullName);
    > > */
    > >
    > > this.myLabel.ForeColor=System.Drawing.Color.Red;
    > > this.myLabel.Text=msg;
    > > }
    > >
    > > When I remove commented section, this method does not show the message in
    > > myLabel on my page, where is the problem?
    > >
    > >

    >
    >
    >
     
    =?Utf-8?B?SklNLkgu?=, Sep 24, 2006
    #3
  4. Sure, don't include any code that generates HTML in your page.

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Software Composer
    http://unclechutney.blogspot.com

    A watched clock never boils.

    "JIM.H." <> wrote in message
    news:...
    > Thanks Kevin, I am trying to make sure I am getting open/save dialog box,
    > any
    > solution for me?
    >
    > "Kevin Spencer" wrote:
    >
    >> The problem is that you're not sending an HTML document to the client.
    >> You
    >> are sending a binary file.
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> Software Composer
    >> http://unclechutney.blogspot.com
    >>
    >> A watched clock never boils.
    >>
    >> "JIM.H." <> wrote in message
    >> news:...
    >> > private void DownloadFile(string fName)
    >> > {
    >> > string msg="download done";
    >> >
    >> > /*
    >> > System.IO.fInfo fInfo = new System.IO.fInfo(fName);
    >> > Response.Clear();
    >> > Response.AddHeader("Content-Disposition", "attachment; filename=" +
    >> > fInfo.Name);
    >> > Response.AddHeader("Content-Length", fInfo.Length.ToString());
    >> > Response.ContentType = "application/octet-stream";
    >> > Response.WriteFile(fInfo.FullName);
    >> > */
    >> >
    >> > this.myLabel.ForeColor=System.Drawing.Color.Red;
    >> > this.myLabel.Text=msg;
    >> > }
    >> >
    >> > When I remove commented section, this method does not show the message
    >> > in
    >> > myLabel on my page, where is the problem?
    >> >
    >> >

    >>
    >>
    >>
     
    Kevin Spencer, Sep 24, 2006
    #4
  5. Ok. How should I show open/save dialog box if an excel file is selected. It
    will open in the browser, that is what we do not want.

    "Kevin Spencer" wrote:

    > Sure, don't include any code that generates HTML in your page.
    >
    > --
    > HTH,
    >
    > Kevin Spencer
    > Microsoft MVP
    > Software Composer
    > http://unclechutney.blogspot.com
    >
    > A watched clock never boils.
    >
    > "JIM.H." <> wrote in message
    > news:...
    > > Thanks Kevin, I am trying to make sure I am getting open/save dialog box,
    > > any
    > > solution for me?
    > >
    > > "Kevin Spencer" wrote:
    > >
    > >> The problem is that you're not sending an HTML document to the client.
    > >> You
    > >> are sending a binary file.
    > >>
    > >> --
    > >> HTH,
    > >>
    > >> Kevin Spencer
    > >> Microsoft MVP
    > >> Software Composer
    > >> http://unclechutney.blogspot.com
    > >>
    > >> A watched clock never boils.
    > >>
    > >> "JIM.H." <> wrote in message
    > >> news:...
    > >> > private void DownloadFile(string fName)
    > >> > {
    > >> > string msg="download done";
    > >> >
    > >> > /*
    > >> > System.IO.fInfo fInfo = new System.IO.fInfo(fName);
    > >> > Response.Clear();
    > >> > Response.AddHeader("Content-Disposition", "attachment; filename=" +
    > >> > fInfo.Name);
    > >> > Response.AddHeader("Content-Length", fInfo.Length.ToString());
    > >> > Response.ContentType = "application/octet-stream";
    > >> > Response.WriteFile(fInfo.FullName);
    > >> > */
    > >> >
    > >> > this.myLabel.ForeColor=System.Drawing.Color.Red;
    > >> > this.myLabel.Text=msg;
    > >> > }
    > >> >
    > >> > When I remove commented section, this method does not show the message
    > >> > in
    > >> > myLabel on my page, where is the problem?
    > >> >
    > >> >
    > >>
    > >>
    > >>

    >
    >
    >
     
    =?Utf-8?B?SklNLkgu?=, Sep 24, 2006
    #5
  6. Here are some references you can use:

    http://msdn.microsoft.com/library/d...fsystemwebhttpresponseclasswritefiletopic.asp
    http://support.microsoft.com/default.aspx?scid=kb;en-us;307603

    --
    HTH,

    Kevin Spencer
    Microsoft MVP
    Software Composer
    http://unclechutney.blogspot.com

    A watched clock never boils.

    "JIM.H." <> wrote in message
    news:...
    > Ok. How should I show open/save dialog box if an excel file is selected.
    > It
    > will open in the browser, that is what we do not want.
    >
    > "Kevin Spencer" wrote:
    >
    >> Sure, don't include any code that generates HTML in your page.
    >>
    >> --
    >> HTH,
    >>
    >> Kevin Spencer
    >> Microsoft MVP
    >> Software Composer
    >> http://unclechutney.blogspot.com
    >>
    >> A watched clock never boils.
    >>
    >> "JIM.H." <> wrote in message
    >> news:...
    >> > Thanks Kevin, I am trying to make sure I am getting open/save dialog
    >> > box,
    >> > any
    >> > solution for me?
    >> >
    >> > "Kevin Spencer" wrote:
    >> >
    >> >> The problem is that you're not sending an HTML document to the client.
    >> >> You
    >> >> are sending a binary file.
    >> >>
    >> >> --
    >> >> HTH,
    >> >>
    >> >> Kevin Spencer
    >> >> Microsoft MVP
    >> >> Software Composer
    >> >> http://unclechutney.blogspot.com
    >> >>
    >> >> A watched clock never boils.
    >> >>
    >> >> "JIM.H." <> wrote in message
    >> >> news:...
    >> >> > private void DownloadFile(string fName)
    >> >> > {
    >> >> > string msg="download done";
    >> >> >
    >> >> > /*
    >> >> > System.IO.fInfo fInfo = new System.IO.fInfo(fName);
    >> >> > Response.Clear();
    >> >> > Response.AddHeader("Content-Disposition", "attachment; filename=" +
    >> >> > fInfo.Name);
    >> >> > Response.AddHeader("Content-Length", fInfo.Length.ToString());
    >> >> > Response.ContentType = "application/octet-stream";
    >> >> > Response.WriteFile(fInfo.FullName);
    >> >> > */
    >> >> >
    >> >> > this.myLabel.ForeColor=System.Drawing.Color.Red;
    >> >> > this.myLabel.Text=msg;
    >> >> > }
    >> >> >
    >> >> > When I remove commented section, this method does not show the
    >> >> > message
    >> >> > in
    >> >> > myLabel on my page, where is the problem?
    >> >> >
    >> >> >
    >> >>
    >> >>
    >> >>

    >>
    >>
    >>
     
    Kevin Spencer, Sep 24, 2006
    #6
    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. walala
    Replies:
    3
    Views:
    2,217
    Ralf Hildebrandt
    Sep 10, 2003
  2. willem oosthuizen

    What is wrong with the following code?

    willem oosthuizen, Oct 10, 2003, in forum: VHDL
    Replies:
    9
    Views:
    1,308
  3. Matthew
    Replies:
    7
    Views:
    739
    Priscilla Walmsley
    Jan 7, 2005
  4. David. E. Goble
    Replies:
    9
    Views:
    492
    David. E. Goble
    Feb 2, 2005
  5. kiran
    Replies:
    12
    Views:
    1,153
    Scott Sauyet
    Dec 7, 2011
Loading...

Share This Page