Tabled of Contents |
---|
- Save the generated Word file to disk .
- Stream the Word file to the client and open it in the browser window .
- Stream the Word file to the client and open it in the default application for .doc and .docx Files .
- Save the generated Word file on the server and stream it to the client .
- Pass the template to WordApplication .
Save to Disk
To save the generated file on the server:
Pass the Save method a file path, for example:
OR
Pass the Save method a System.IO.FileStream object, for example:
Open in the Browser
When you pass an HttpResponse object to Save, WordWriter will stream the generated Word file to the client. The browser will display a File Download dialog asking the user to open or save the file. The method's second parameter specifies a file name to display in the File Download dialog. If the method's third parameter - OpenInBrowser - is True and the user chooses to open the Word file, the file will open in the browser window.
Alternatively, stream the file to the browser by passing Response.Stream to the Save method. In this case, to open the generated file in the browser window:
Set the response's content-type header to "application/vnd.ms-word":
Set the response's content-disposition to "inline":
Pass the Save method Response.Stream as a parameter:
Open in the Default Application for .doc or .docx Files
When you pass an HttpResponse object to Save, WordWriter will stream the generated Word file to the client. The browser will display a File Download dialog asking the user to open or save the file. The method's second parameter specifies a file name to display in the File Download dialog. If the method's third parameter - OpenInBrowser - is False and the user chooses to open the Word file, the file will open in the default application for .doc or .docx files (such as Microsoft Word, StarOffice, or OpenOffice.org).
Alternatively, stream the file to the browser by passing Response.Stream to the Save method. In this case, to open the generated file in the default application for Word files:
Set the response's content-type header to "application/vnd.ms-word":
C#VB.NETSet the response's content-disposition to "attachment":
C#VB.NETPass the Save method Response.Stream as a parameter:
C#VB.NET
Save and Stream to Browser
You can call Save more than once for a single instance of WordTemplate. In the following examples Save is called twice:
Saves the generated Word file on the server.
Streams the generated Word file to the client. Since the parameter OpenInBrowser is False, the file will open in the default application for .doc files.
Pass the Template to WordApplication
You can use WordTemplate to open and populate a WordWriter template, then pass the populated workbook to WordApplication for additional processing. In this case, do not call Save. Instead, pass the WordTemplate object to WordApplication's Open method: