SaveAs method (DataWindows)
Description
Saves the contents of a DataWindow or DataStore in the format
you specify.
For syntax to save the contents of graphs
in DataWindows and DataStores, see SaveAs. For syntax
to save objects in OLE controls and OLE storage, see SaveAs in
the PowerScript Reference.
Controls
DataWindow type |
Method applies to |
---|---|
PowerBuilder |
DataWindow control, DataWindowChild object, DataStore |
Web |
Server component |
Syntax
[PowerBuilder]
1 |
integer <span>dwcontrol</span>.<span>SaveAs</span> ( { string <span>filename</span>, saveastype <span>saveastype</span>,<br> boolean <span>colheading</span> { , <span>encoding encoding</span> } } ) |
[Web DataWindow server component]
1 |
short <span>dwcontrol</span>.<span>SaveAs</span> ( string <span>filename</span>, string <span>saveastype</span>, <br> boolean <span>colheading</span> )<br>short <span>dwcontrol</span>.<span>SaveAsEx</span> ( string <span>filename</span>, string <span>saveastype</span>, <br> boolean <span>colheading, </span><span>string encoding</span> ) |
1 |
Argument |
Description |
---|---|
dwcontrol |
A reference to a DataWindow control, |
filename (optional |
A string whose value is the name of the ![]() If you are working with a DataStore, you must supply the filename argument. |
saveastype (optional |
A value of the SaveAsType enumerated For a list of values, see SaveAsType. |
colheading (optional |
A boolean value indicating whether you |
encoding (optional |
Character encoding of the file to which
|
Return Values
Returns 1 if it succeeds and –1 if an error occurs.
If any argument’s value is null, SaveAs returns
null.
Usage
If you do not specify any arguments for SaveAs,
PowerBuilder displays the Save As dialog box. A drop-down list lets the user
specify the format of the saved data. You must specify all arguments
for the Web DataWindow.
Report format (PSReport! value of SaveAsType) is the best
choice if the DataWindow is a composite report. Choosing PSReport!
has no effect if the DataWindow object has the RichText presentation
style.
For XML!, the XML logical structure used is based on the current
XML export template for the DataWindow object. You can change the
export template by setting the value of the Export.XML.UseTemplate
property. If no export template is specified, the default template
is used.
If you use date formats in your report, you must verify that
yyyy is the Short Date Style for year in the Regional Settings of
the user’s Control Panel. Your program can check this with
the RegistryGet function. If the setting is not
correct, you can ask the user to change it manually or to have the
application change it (by calling the RegistrySet function).
The user might need to reboot after the setting is changed.
When you save the contents of a DataWindow to a text file,
double quotes are handled in a way that enables the ImportFile method
to produce the same DataWindow when the text file is imported back
into PowerBuilder. Any field that is enclosed in a pair of double
quotes is wrapped with three pairs of double quotes in the saved
text file. Double quotes at the beginning of a text field that have
no matching double quotes at the end of the field are also replaced
by three double quotes in the saved text file. However, a double
quote elsewhere in the field is saved as one double quote.
The behavior of the SaveAs method with
the EncodingANSI! parameter or with no encoding parameter is platform
dependent. On the Windows and Solaris platforms, the file is always
saved with ANSI encoding whether you are connected to an ANSI or
Unicode database. On the Linux platform with an ANSI database connection, SaveAs saves
the file with ANSI encoding. On the Linux platform with a Unicode
database connection, if the data contains multilanguage characters, SaveAs converts
the characters to UTF-8 and saves the file with UTF-8 encoding.

The Web ActiveX is a safely scriptable control and does not
take actions that can affect the client’s environment.
Therefore, it does not support SaveAs.
Examples
This statement saves the contents of dw_History
to the file G:INVENTORYEMPLOYEE.HIS.
The saved file is in CSV format without column headings:
1 |
dw_History.<span>SaveAs</span>("G:INVENTORYEMPLOYEE.HIS", &<br>   CSV!, false) |
The following statements set the template used by
the DataWindow dw_1 to t_report,
specify that metadata in the XMLSchema! format
should be generated in a separate file, and generate the files c:myxml.xml containing the
DataWindow row data in XML format, and c:myxml.xsd containing the
XML schema used in c:myxml.xml:
1 |
dw_1.Modify("DataWindow.Export.XML.UseTemplate =<br>   't_report'")<br>dw_1.Modify("DataWindow.Export.XML.MetaDataType =<br>   XMLSchema!")<br>dw_1.Modify("DataWindow.Export.XML.SaveMetaData =<br>   MetaDataExternal!")<br>dw_1.SaveAs("c:myxml.xml", XML!, false) |
The following statements generate the files c:dw_one.fo containing
the DataWindow presentation and data in XSL-FO format, and c:dw_one.pdf containing
the DataWindow presentation and data in PDF format:
1 |
dw_1.SaveAs("c:dw_one.fo", XSLFO!, false)<br>dw_1.SaveAs("c:dw_one.pdf", PDF!, false) |