Output Options |
 |
WordWriter's Save method
generates a new Word file and either saves it on the server, or streams it to the
browser. WordWriter can:
| When WordWriter streams a file to the client, the output result
will depend on the browser as well as the server-side script. |
| Save to disk | To save the generated file
on the server:
- Pass the
Save method
a file path, for example:oWW.Save("c:\Documents\File.doc")
OR
Pass the Save method a System.IO.FileStream
object. For example:
oFileStream = New FileStream(Server.MapPath("./StreamOutput.doc"), FileMode.Create)
...
oWW.Save(oFileStream)
...
If Not oFileStream Is Nothing Then
oFileStream.Close()
End If
VB.NET Example
|
C# 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.
For example:
oWW.Save(Page.Response, "StringVarOutput.doc", True)
VB.NET Example
|
C# Example
|
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":
Response.ContentType = "application/vnd.ms-word"
- Set the response's content-disposition to
"inline":
Response.AddHeader("Content-Disposition", "inline;filename=""WordWriter.doc""")
- Pass the
Save method
Response.Stream as a parameter:
oWW.Save(Response.OutputStream)
|
| Open in Microsoft Word |
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 Microsoft Word. For Example:
oWW.Save(Page.Response, "StringVarOutput.doc", False)
VB.NET Example
|
C# Example
|
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 Microsoft Word:
- Set the response's content-type header to
"application/vnd.ms-word":
Response.ContentType = "application/vnd.ms-word"
- Set the response's content-disposition to
"attachment":
Response.AddHeader("Content-Disposition", "attachment;filename=""WordWriter.doc""")
- Pass the
Save method
Response.Stream as a parameter:
oWW.Save(Response.OutputStream)
|
| 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:
oWW.Save(Server.MapPath("./SaveMultipleOutput.doc"))
Saves the generated Word file on the server.
oWW.Save(Page.Response, "SaveMultipleOutput.doc", False)
Streams the generated Word file to the client. Since the parameter
OpenInBrowser is False, the file will open in Microsoft Word.
VB.NET Example
|
C# Example
|
|
|---|
Copyright © 2003, SoftArtisans, Inc.