Page tree

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Excerpt IncludeWW8:WordApplication in DepthWW8:WordApplication in Depthnopaneltrue

Table of Contents

Table of Contents

After creating a document with WordApplication, you can:

Note

When WordWriter streams a file to the client, the output result will depend on the browser as well as the server-side script.

Anchor
save
save

Save to Disk

To save the generated file on the server, call:

Code Block
void Save(Document doc,
	bool preserve,
	String fileName)

If preserve is true, WordWriter will try to preserve all formatting and features in the file, including those that it does not directly support. These includes fields, footnotes, hyperlinks, comments, and anchored images. If preserve is false, only features directly supported by WordWriter will be preserved. These includes all tables, lists, headers, and footers. Setting preserve to false will produce a much smaller file.

fileName specifies a complete physical path and file name for the generated file. WordWriter will save the file to this location. If a file with the same name exists, it will be overwritten by the new Word file.

Example

Code Block
c#
c#
WordApplication wwapp = new WordApplication();
Document doc = wwapp.Create();
wwapp.Save(doc, false, @"C:\Sales2003\June.doc");

Anchor
browser
browser

Stream to Client

To stream the generated file to the client, call one of the following methods:

Code Block
void Save(Document doc,
     bool preserve,
     System.Web.HttpResponse response,
     String fileName,
     bool openInBrowser)

void Save(Document doc,
     bool preserve,
     System.Web.HttpResponse response,
     String fileName,
     bool openInBrowser,
     String contentType)

If preserve is true, WordWriter will try to preserve all formatting and features in the file, including those that it does not directly support. These includes fields, footnotes, hyperlinks, comments, and anchored images. If preserve is false, only features directly supported by WordWriter will be preserved. These includes all tables, lists, headers, and footers. Setting preserve to false will produce a much smaller file.

fileName specifies a complete physical path and file name for the generated file. WordWriter will save the file to this location. If a file with the same name exists, it will be overwritten by the new Word file.

Browsers other than Internet Explorer cannot embed a Word file in the browser window. When the generated document is streamed to a browser other than IE, the user will always be prompted to open or save the file. If the user chooses to open the file, it will open in Microsoft Word or another document application.

Internet Explorer can display a Word file in the browser window. When the generated document is streamed to Internet Explorer, the browser's settings will determine whether the file opens automatically or the user is asked to open or save the file. The parameter openInBrowserdetermines whether the file will open in IE or in a document application. If openInBrowser is set to true, the response content-disposition header is set to open the file in the browser window.

Example

Code Block
c#
c#
WordApplication wwapp = new WordApplication();
Document doc = wwapp.Create();
wwapp.Save(doc,
     false,
     Page.Response,
     "file.doc",
     true,
     "application/vnd.ms-word");

Anchor
stream
stream

Write to Stream

To write the generated document to a System.IO.Stream, call:

Code Block
void Save(Document doc,
     bool preserve,
     OutputStream out)

If preserve is true, WordWriter will try to preserve all formatting and features in the file, including those that it does not directly support. These includes fields, footnotes, hyperlinks, comments, and anchored images. If preserve is false, only features directly supported by WordWriter will be preserved. These includes all tables, lists, headers, and footers. Setting preserve to false will produce a much smaller file.

Example

Code Block
c#
c#
WordApplication wwapp = new WordApplication();
Document doc = wwapp.Create();
System.IO.Stream fstream = new System.IO.FileStream (@"C:\file.doc", FileMode.Create);
wwapp.Save(doc, false, fstream);

Anchor
template
template

Return a Template

You can use WordApplication to create a document with merge fields (i.e., a template) and pass the file to WordTemplate to populate the merge fields. To pass a document to WordTemplate, use the following method:

Code Block
WordTemplate.Open(WordApplication aApp, Document aDoc)

Example

Code Block
c#
c#
WordApplication wwApp = new WordApplication();
Document doc = wwApp.Create();
WordTemplate wwTmpl = New WordTemplate();
wwTmpl.Open(wwApp, doc);