some difficulties when displaying page content in MS Word format

S

sonic

Hi,
displaying information on a page as MS Word document seems to be as
simple as:

//OnLoad
Response.ContentType = "application/msword";
Response.Write ( MyContentString );

(this assuming intranet site environment with users ensured to use
certain version of MS Word on their workstations)

I am getting following 2 problems :
It seems that, when the content exceeds certain size, instead of
browser automatically loading content in ms word editor, it pops up the
"File Downlaod" dialog with Filename: MyPage.aspx which contains the
full HTML for the page.
Any idea why this happens ?

another problem is that in some cases i get the "convert file" dialog
which has "RTF" etc choices in the list box.

anyone knows what is causing those dialogs and how i could ensure they
don't pop up ?
TIA.
 
S

Steve C. Orr [MVP, MCSD]

For one thing, you need to specify a filename with a line like this:

Response.AddHeader("Content-Disposition", "inline;filename=test.doc")

As far as the convert dialog goes, it sounds like you might be outputting a
format with which Word is not familiar. It understands basic HTML for
example, so you could give it that.

Here's a bunch more information for you along with code samples:
http://steveorr.net/articles/ExcelExport.aspx
http://steveorr.net/articles/ExportPanel.aspx
 
S

sonic

Hi Steve,
I actually experimented with the content as HTML, and in the end was
outputting plain unformatted string with 2 words, while still getting
that convert file dialog. but i did not try messing with headers yet,
thanks for the suggestion and links !
 
S

sonic

ahh, it looks like i found the problem.

it looks like viewstate was being rendered into the word doc and when
it grew in size, word would not recognize the content as its own..

so i overwrote the page Render event, and instead of calling
base.Render() i only render the elements that hold the content that
needs to go into word document.
like this:

protected override void Render(System.Web.UI.HtmlTextWriter writer)
{
if (!_displayWordFormat)
base.Render (writer);
else
DocumentContent.RenderControl( writer );
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top