|
Programmer's Reference
> WordTemplate
> Save Method
Save(FileName)
C# Syntax:
public void Save(string strFilePath);
VB.NET Syntax:
Public Sub Save(strFilePath As String)
Object:
Description:
Saves the generated Word file on the server.
You can call Save more than once for a single instance of
WordTemplate. This allows you to save more than one copy
of a generated file, and/or both save the file on the server and stream it to the client.
Using multiple Process and Save calls,
you can generate multiple files from a single template and an updated data source.
Parameters:
strFilePath
Specifies a complete 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.
Exceptions:
Example:
[VB.NET]
oWW = New WordTemplate()
oWW.Open("c:\templates\Template.doc")
oWW.SetDataSource(arrValue, arrName)
oWW.Process()
oWW.Save("c:\reports\Report.doc")
save(oStreamObj)
C# Syntax:
public void Save(System.IO.Stream oStreamObj);
VB.NET Syntax:
Public Sub Save(oStreamObj As System.IO.Stream)
Object:
Description:
Sends the generated Word binary file to the specified
System.IO.Stream or, a class derived from
System.IO.Stream (for example, System.IO.FileStream).
If you pass Save a System.IO.FileStream, WordWriter will save
the generated file on the server. If you pass Save Response.OutputStream,
WordWriter will stream the the generated file to the client.
You can call Save more than once for a single instance of
WordTemplate. This allows you to save more than one copy
of a generated file, and/or both save the file on the server and stream it to the client.
Using multiple Process and Save calls,
you can generate multiple files from a single template and an updated data source.
Parameters:
oStreamObj
A System.IO.Stream object (for example, Response.OutputStream)
or, a class derived from System.IO.Stream (for example,
System.IO.FileStream)
Exception:
Example:
[C#]
//--- Open a FileStream object, pass it to
//--- the Save method, and close the FileStream object.
FileStream oFileStream = new
FileStream(@"c:\temp\StreamOutput.doc", FileMode.Create);
...
oWW.Save(oFileStream);
...
//--- Could put this in a finally block
if(oFileStream!=null)
oFileStream.Close();
[VB.NET]
'--- Open a FileStream object, pass it to
'--- the Save method, and close the FileStream object.
Dim oFileStream As New FileStream("c:\temp\StreamOutput.doc", _
FileMode.Create)
...
oWW.Save(oFileStream)
...
If Not oFileStream Is Nothing Then
oFileStream.Close()
End If
save(response)
C# Syntax:
public void Save(System.Web.HttpResponse response);
VB.NET Syntax:
Public Sub Save(response As System.Web.HttpResponse)
Object:
Description:
If you pass Save an HttpResponse object
object, WordWriter will stream the generated file to the client. If the user
chooses to open (rather than save) the file, it will open in the browser window.
You can call Save more than once for a single instance of
WordTemplate. This allows you to save more than one copy
of a generated file, and/or both save the file on the server and stream it to the client.
Using multiple Process and Save calls,
you can generate multiple files from a single template and an updated data source.
Parameter:
response
The page's HttpResponse object.
Exception:
Example:
[C#]
...
WordTemplate oWW = new WordTemplate();
oWW.Open(Server.MapPath("./StringVarTemplate.doc"));
oWW.SetDataSource(MyDataTable);
oWW.Process();
oWW.Save(Page.Response);
[VB.NET]
...
Dim oWW As New WordTemplate()
oWW.Open(Server.MapPath("./StringVarTemplate.doc"))
oWW.SetDataSource(MyDataTable)
oWW.Process()
oWW.Save(Page.Response)
save(response, attachmentName, openInBrowser)
C# Syntax:
public void Save(System.Web.HttpResponse response,
string attachmentName,
bool openInBrowser);
VB.NET Syntax:
Public Sub Save(response As System.Web.HttpResponse,_
attachmentName As String,_
OpenInBrowser As Boolean)
Object:
Description:
If you pass save an HttpServletResponse object, WordWriter will
stream the generated file to the client. This method allows you to specify a
default client-side file name, and whether the file should be opened in the browser
window or in Microsoft Word.
You can call Save more than once for a single instance of
WordTemplate. This allows you to save more than one copy
of a generated file, and/or both save the file on the server and stream it to the client.
Using multiple Process and Save calls,
you can generate multiple files from a single template and an updated data source.
Parameters:
response
The HttpResponse instance of the page.
attachmentName
Specifies a name for the generated Word file; this name will be displayed in the
download dialog when the file is streamed to the browser.
openInBrowser
If openInBrowser is set to true, and the
user chooses to open the file, the file will open in the browser
window. If openInBrowser is set to false, and the
user chooses to open the file, the file will open in Microsoft Word.
By default, the file will open in the browser window. Note: not all
browsers can embed a Word file in the browser window.
Exception:
Examples:
Stream to the client and open in MS 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.
[C#]
oWW.Save(Page.Response, "StringVarOutput.doc", false);
[VB.NET]
oWW.Save(Page.Response, "StringVarOutput.doc", False)
Stream to the client and open in the browser window
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.
[C#]
oWW.Save(Page.Response, "StringVarOutput.doc", true);
[VB.NET]
oWW.Save(Page.Response, "StringVarOutput.doc", True)

Copyright 2006 © SoftArtisans, Inc. All Rights Reserved.
|