SaveDocument

Description

Saves the contents of a RichTextEdit control in a file. You can specify either rich-text format (RTF) or text format for the file.

Applies to

RichTextEdit controls

Syntax

rtename.SaveDocument ( filename {, filetype {, encoding }} )

Argument

Description

rtename

The name of the RichTextEdit control whose contents you want to save.

filename

A string whose value is the name of the file to be saved. If the file already exists, the FileExists event is triggered.

filetype 

(optional)

A value of the FileType enumerated datatype specifying the format of the saved file. Values are:

  • FileTypeRichText! -- Save the file in rich text format

  • FileTypeText! -- Save the file as text

  • FileTypeDoc! -- Save the file in Microsoft Word format

  • FileTypeHTML! -- Save the file in HTML format

  • FileTypePDF! -- Save the file in PDF format

encoding (optional)

Character encoding of the file to which the data is saved. This parameter applies only to text files. If you do not specify an encoding parameter, the file is saved in ANSI format.

The filetype argument must be set to FileTypeText! If the filetype argument is set to any other file type, this argument is ignored. Values are:

  • EncodingANSI! (default)

  • EncodingUTF8!

  • EncodingUTF16LE!

  • EncodingUTF16BE!


Return value

Integer.

Returns 1 if it succeeds and -1 if an error occurs.

Usage

SaveDocument triggers a FileExists event when the file you name already exists. If you do not specify a filetype, SaveDocument saves the file as a text file if you specify a file name with the extension .txt, as a Microsoft Word document if you specify a file name with the extension .doc, and as an RTF file if you specify a file name with the .rtf extension.

The format that you specify in the encoding argument is valid only if you specified FileTypeText! for the filetype argument. SaveDocument saves text in ANSI format only for all other file types.

Examples

This code for a CommandButton saves the document in the RichTextEdit rte_1:

integer li_rtn
li_rtn = rte_1.SaveDocument("c:\test.rtf", &
FileTypeRichText!)

If the file TEST.RTF already exists, PowerBuilder triggers the FileExists event with the following script. OpenWithParm displays a response window that asks the user if it is OK to overwrite the file. The return value from FileExists determines whether the file is saved:

OpenWithParm( w_question, &
      "The specified file already exists. " + &
         "Do you want to overwrite it?" )
IF Message.StringParm = "Yes" THEN
      RETURN 0  // File is saved
ELSE
      RETURN -1 // Saving is canceled
END IF

This code for a CommandButton saves the document in the RichTextEdit rte_1 in a text file with UTF-16LE encoding:

integer li_rtn
li_rtn = rte_1.SaveDocument("c:\test.txt", &
   FileTypeText!, EncodingUTF16LE!)

See also

InsertDocument