By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,811 Members | 785 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,811 IT Pros & Developers. It's quick & easy.

Open web page in WORD

P: n/a
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
Nov 19 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a

"Senol Akbulak" <se**********@newsgroup.nospam> wrote in message
news:26**********************************@microsof t.com...
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

Nov 19 '05 #2

P: n/a
My form content is for html. Is the problem that?
Cannot Word open html content?

"Andy Fish" wrote:

"Senol Akbulak" <se**********@newsgroup.nospam> wrote in message
news:26**********************************@microsof t.com...
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


Nov 19 '05 #3

P: n/a
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" <se**********@newsgroup.nospam> wrote in message
news:8A**********************************@microsof t.com...
My form content is for html. Is the problem that?
Cannot Word open html content?

"Andy Fish" wrote:

"Senol Akbulak" <se**********@newsgroup.nospam> wrote in message
news:26**********************************@microsof t.com...
> 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


Nov 19 '05 #4

P: n/a
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.)


Nov 19 '05 #5

P: n/a
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.)


Nov 19 '05 #6

P: n/a
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.)

Nov 19 '05 #7

P: n/a
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.)

Nov 19 '05 #8

P: n/a
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.)

Nov 19 '05 #9

P: n/a
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 ***
Nov 19 '05 #10

P: n/a
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 ***


Nov 19 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.