Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Open web page in WORD

Reply
Thread Tools

Open web page in WORD

 
 
=?Utf-8?B?xZ5lbm9sIEFrYnVsYWs=?=
Guest
Posts: n/a
 
      03-18-2005
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
 
Reply With Quote
 
 
 
 
Andy Fish
Guest
Posts: n/a
 
      03-18-2005

"Senol Akbulak" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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



 
Reply With Quote
 
 
 
 
=?Utf-8?B?xZ5lbm9sIEFrYnVsYWs=?=
Guest
Posts: n/a
 
      03-18-2005
My form content is for html. Is the problem that?
Cannot Word open html content?

"Andy Fish" wrote:

>
> "Senol Akbulak" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
> > 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

>
>
>

 
Reply With Quote
 
Andy Fish
Guest
Posts: n/a
 
      03-18-2005
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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> My form content is for html. Is the problem that?
> Cannot Word open html content?
>
> "Andy Fish" wrote:
>
>>
>> "Senol Akbulak" <(E-Mail Removed)> wrote in message
>> news:(E-Mail Removed)...
>> > 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

>>
>>
>>



 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      03-21-2005
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.)






 
Reply With Quote
 
=?Utf-8?B?xZ5lbm9sIEFrYnVsYWs=?=
Guest
Posts: n/a
 
      03-24-2005
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.)
>
>
>
>
>
>
>

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      03-25-2005
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.)

 
Reply With Quote
 
=?Utf-8?B?xZ5lbm9sIEFrYnVsYWs=?=
Guest
Posts: n/a
 
      03-25-2005
Thank you at all!!!

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

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.)
>
>

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      03-28-2005
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.)

 
Reply With Quote
 
John
Guest
Posts: n/a
 
      04-06-2005
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 ***
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Word 2007 XML/ZIP files, older Word and/or Open Office Steve Freides Computer Support 1 01-29-2010 02:28 AM
Open Word Document from a Dialog Web Page Peter ASP .Net 7 05-02-2008 07:22 PM
Open MS Word 2003 document from VS2005- ASP.NET web page- Help nee Ravi ASP .Net 1 01-14-2008 06:56 PM
Open Word Doc in Word, not in Browser Franck ASP .Net 1 09-09-2005 07:37 AM
Open Word Perfect File in MSFT Word??? WeeWilly Computer Support 2 01-04-2004 01:33 AM



Advertisments