Open web page in WORD

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

  1. Hi,

    I have a form page to print on my web application(asp.net). I want to show
    the page in WORD. I use that code in asp.net Page_Load event:
    Response.Clear();
    Response.ContentType = "application/ms-word";
    Response.AddHeader("Content-Disposition", "attachment;filename=word.doc");

    When I open the page in IE shows a dialog to ask whether I want to open or
    save. It is ok. But when I click Open or Save button, I get an error message:
    "
    Internet Explorer cannot download form.aspx.
    Internet Explorer was not able to open this Internet site. The requested
    site is either unavailable or cannot be found. Please try again later.
    "

    What can I do to solve this problem?

    Thanks in advance.

    --
    ______________________________
    Åženol Akbulak
    =?Utf-8?B?xZ5lbm9sIEFrYnVsYWs=?=, Mar 18, 2005
    #1
    1. Advertising

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

    Andy Fish Guest

    "Senol Akbulak" <> wrote in message
    news:...
    > Hi,
    >
    > I have a form page to print on my web application(asp.net). I want to show
    > the page in WORD. I use that code in asp.net Page_Load event:
    > Response.Clear();
    > Response.ContentType = "application/ms-word";
    > Response.AddHeader("Content-Disposition", "attachment;filename=word.doc");
    >
    > When I open the page in IE shows a dialog to ask whether I want to open or
    > save. It is ok. But when I click Open or Save button, I get an error
    > message:
    > "
    > Internet Explorer cannot download form.aspx.
    > Internet Explorer was not able to open this Internet site. The requested
    > site is either unavailable or cannot be found. Please try again later.
    > "
    >
    > What can I do to solve this problem?
    >


    hmm, it looks as if you are doing the right thing.

    I presume you are streaming the binary contents of a word document directly
    after setting these headers. Have you checked the document itself is being
    sent correctly.

    you could also try putting in a content-length header but I wouldn't have
    thought this was necessary.


    > Thanks in advance.
    >
    > --
    > ______________________________
    > Senol Akbulak
    Andy Fish, Mar 18, 2005
    #2
    1. Advertising

  3. My form content is for html. Is the problem that?
    Cannot Word open html content?

    "Andy Fish" wrote:

    >
    > "Senol Akbulak" <> wrote in message
    > news:...
    > > Hi,
    > >
    > > I have a form page to print on my web application(asp.net). I want to show
    > > the page in WORD. I use that code in asp.net Page_Load event:
    > > Response.Clear();
    > > Response.ContentType = "application/ms-word";
    > > Response.AddHeader("Content-Disposition", "attachment;filename=word.doc");
    > >
    > > When I open the page in IE shows a dialog to ask whether I want to open or
    > > save. It is ok. But when I click Open or Save button, I get an error
    > > message:
    > > "
    > > Internet Explorer cannot download form.aspx.
    > > Internet Explorer was not able to open this Internet site. The requested
    > > site is either unavailable or cannot be found. Please try again later.
    > > "
    > >
    > > What can I do to solve this problem?
    > >

    >
    > hmm, it looks as if you are doing the right thing.
    >
    > I presume you are streaming the binary contents of a word document directly
    > after setting these headers. Have you checked the document itself is being
    > sent correctly.
    >
    > you could also try putting in a content-length header but I wouldn't have
    > thought this was necessary.
    >
    >
    > > Thanks in advance.
    > >
    > > --
    > > ______________________________
    > > Senol Akbulak

    >
    >
    >
    =?Utf-8?B?xZ5lbm9sIEFrYnVsYWs=?=, Mar 18, 2005
    #3
  4. =?Utf-8?B?xZ5lbm9sIEFrYnVsYWs=?=

    Andy Fish Guest

    hmm,

    Well, word can certainly open an HTML file, but I wouldn't be at all
    surprised if streaming HTML content to the browser with a content-type of
    word didn't work.

    Bear in mind that with content type you are supposed to be telling the
    browser what type of file you are sending, and the browser is in charge of
    deciding which application to use. There is no way in HTTP of saying "here's
    some HTML, open it with word".

    Andy

    "Senol Akbulak" <> wrote in message
    news:...
    > My form content is for html. Is the problem that?
    > Cannot Word open html content?
    >
    > "Andy Fish" wrote:
    >
    >>
    >> "Senol Akbulak" <> wrote in message
    >> news:...
    >> > Hi,
    >> >
    >> > I have a form page to print on my web application(asp.net). I want to
    >> > show
    >> > the page in WORD. I use that code in asp.net Page_Load event:
    >> > Response.Clear();
    >> > Response.ContentType = "application/ms-word";
    >> > Response.AddHeader("Content-Disposition",
    >> > "attachment;filename=word.doc");
    >> >
    >> > When I open the page in IE shows a dialog to ask whether I want to open
    >> > or
    >> > save. It is ok. But when I click Open or Save button, I get an error
    >> > message:
    >> > "
    >> > Internet Explorer cannot download form.aspx.
    >> > Internet Explorer was not able to open this Internet site. The
    >> > requested
    >> > site is either unavailable or cannot be found. Please try again later.
    >> > "
    >> >
    >> > What can I do to solve this problem?
    >> >

    >>
    >> hmm, it looks as if you are doing the right thing.
    >>
    >> I presume you are streaming the binary contents of a word document
    >> directly
    >> after setting these headers. Have you checked the document itself is
    >> being
    >> sent correctly.
    >>
    >> you could also try putting in a content-length header but I wouldn't have
    >> thought this was necessary.
    >>
    >>
    >> > Thanks in advance.
    >> >
    >> > --
    >> > ______________________________
    >> > Senol Akbulak

    >>
    >>
    >>
    Andy Fish, Mar 18, 2005
    #4
  5. Hi Senol,

    I think Andy's suggestions are reasonable. Though WORD can open HTML
    document correcdtly. The IE browser will check the mime-type of the
    response stream first. If we output an HTML document but set the content
    Type as word, that'll cause the problem. So I suggest you consider the
    following options:
    1. Convert the content to word compatible document (word or normal rtf)

    2. Use text/html as the response's content Type. We can use

    Response.AddHeader("Content-Disposition", "attachment;filename=xxxx");

    to let the document be opened outside, but whether it'll be opened through
    Word.exe will depened on the clientside's settings.

    Please feel free to post here if you have any further questions. Thanks,

    Regards,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], Mar 21, 2005
    #5
  6. Hi Steven,

    I sorry, I just realized your answer.

    I tried your second suggest, but I still get the same error message.

    "Steven Cheng[MSFT]" wrote:

    > Hi Senol,
    >
    > I think Andy's suggestions are reasonable. Though WORD can open HTML
    > document correcdtly. The IE browser will check the mime-type of the
    > response stream first. If we output an HTML document but set the content
    > Type as word, that'll cause the problem. So I suggest you consider the
    > following options:
    > 1. Convert the content to word compatible document (word or normal rtf)
    >
    > 2. Use text/html as the response's content Type. We can use
    >
    > Response.AddHeader("Content-Disposition", "attachment;filename=xxxx");
    >
    > to let the document be opened outside, but whether it'll be opened through
    > Word.exe will depened on the clientside's settings.
    >
    > Please feel free to post here if you have any further questions. Thanks,
    >
    > Regards,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
    >
    >
    >
    >
    >
    =?Utf-8?B?xZ5lbm9sIEFrYnVsYWs=?=, Mar 24, 2005
    #6
  7. Thanks for your followup Senol,

    Well, I'm not sure whether there is something incorrect on your server's
    asp.net/iis environment. But is it ok for you to simple use
    Response.WriteFile to output an existing word or excel document. For
    example:

    private void btnZIP_Click(object sender, System.EventArgs e)
    {
    Response.Clear();
    Response.ContentType="application/msword";
    Response.AddHeader("content-disposition","attachment; filename=mydoc.doc");
    Response.WriteFile(Server.MapPath("~/files/mydoc.doc"));
    Response.End();
    }


    If even this not work, I'm fraid there must be some environment specific
    problems we need to troubleshooting.

    Thanks,

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], Mar 25, 2005
    #7
  8. Thank you at all!!!

    I found the problem. The problem was that:
    ########################################
    Response.Cache.SetCacheability(HttpCacheability.NoCache);
    ########################################

    After deleting this line, it run successfully.

    Thanks.

    "Steven Cheng[MSFT]" wrote:

    > Thanks for your followup Senol,
    >
    > Well, I'm not sure whether there is something incorrect on your server's
    > asp.net/iis environment. But is it ok for you to simple use
    > Response.WriteFile to output an existing word or excel document. For
    > example:
    >
    > private void btnZIP_Click(object sender, System.EventArgs e)
    > {
    > Response.Clear();
    > Response.ContentType="application/msword";
    > Response.AddHeader("content-disposition","attachment; filename=mydoc.doc");
    > Response.WriteFile(Server.MapPath("~/files/mydoc.doc"));
    > Response.End();
    > }
    >
    >
    > If even this not work, I'm fraid there must be some environment specific
    > problems we need to troubleshooting.
    >
    > Thanks,
    >
    > Steven Cheng
    > Microsoft Online Support
    >
    > Get Secure! www.microsoft.com/security
    > (This posting is provided "AS IS", with no warranties, and confers no
    > rights.)
    >
    >
    =?Utf-8?B?xZ5lbm9sIEFrYnVsYWs=?=, Mar 25, 2005
    #8
  9. Thanks for your followup.

    I'm glad that everything works well now.
    Have a good day!

    Steven Cheng
    Microsoft Online Support

    Get Secure! www.microsoft.com/security
    (This posting is provided "AS IS", with no warranties, and confers no
    rights.)
    Steven Cheng[MSFT], Mar 28, 2005
    #9
  10. =?Utf-8?B?xZ5lbm9sIEFrYnVsYWs=?=

    John Guest

    Hi There!

    I followed the same method to open a web form report page in MS word.
    How do I automate the Open [to avoid the file download dialog - would
    you like to open the file or save it to your disk?]

    Your help is greatly appreciated!

    John

    *** Sent via Developersdex http://www.developersdex.com ***
    John, Apr 6, 2005
    #10
  11. =?Utf-8?B?xZ5lbm9sIEFrYnVsYWs=?=

    Brock Allen Guest

    This is a client browser setting. It'd be a security vulnerability if you
    could force an app to open on my machine.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hi There!
    >
    > I followed the same method to open a web form report page in MS word.
    > How do I automate the Open [to avoid the file download dialog - would
    > you like to open the file or save it to your disk?]
    >
    > Your help is greatly appreciated!
    >
    > John
    >
    > *** Sent via Developersdex http://www.developersdex.com ***
    >
    Brock Allen, Apr 6, 2005
    #11
    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. Franck
    Replies:
    1
    Views:
    4,837
  2. Ravi
    Replies:
    1
    Views:
    1,856
    Mark Rae [MVP]
    Jan 14, 2008
  3. Mike Cantelon
    Replies:
    0
    Views:
    260
    Mike Cantelon
    Mar 23, 2008
  4. Peter
    Replies:
    7
    Views:
    548
    Peter
    May 2, 2008
  5. Tao Ji
    Replies:
    1
    Views:
    199
    pharrington
    Feb 4, 2010
Loading...

Share This Page