writeText (NotesStream - JavaScript)

Writes text to a stream.

Defined in

NotesStream

Syntax

writeText(text:string) : int

writeText(text:string, endOfLine:int) : int

Parameter Description
text The text to write, to a maximum of 2GB bytes.
endOfLine End-of-line character(s) appended to the text. The default is NotesStream.EOL_NONE.
  • NotesStream.EOL_CR 2 appends a carriage return (ASCII 13).
  • NotesStream.EOL_CRLF 0 appends a carriage return and line feed (ASCII 10 + 13).
  • NotesStream.EOL_LF 1 appends a line feed (ASCII 10).
  • NotesStream.EOL_NONE 5 appends nothing.
  • NotesStream.EOL_PLATFORM 3 follows the conventions of the current platform.
Return value Description
int The number of characters written.

Usage

This method appends the text to the end of the stream.

This method throws an exception if the stream is read-only. See IsReadOnly.

When a stream is written, property values are:

  • Bytes is incremented by the number of bytes read
  • IsEOS is true
  • Position is set at end of stream

If the stream is opened on an empty file and the character set is Unicode, UTF-16, UTF-16BE, or UTF-16LE, this method writes byte order mark or signature bytes at the beginning of the stream. These bytes are transparent upon subsequent accesses of the stream with the same character set.

Examples

This button writes the subject and body items of the current document to a text file.
var filepath:string = database.getFileName();
filepath = "c:\\" + filepath.left(filepath.length - 3) + "txt";
requestScope.status = "Output file: " + filepath;
var stream:NotesStream = session.createStream();
if (stream.open(filepath, "ASCII")) {
	if (stream.isReadOnly()) {
		requestScope.status = filepath + " is read-only";
		return;
	}
	stream.truncate();
	requestScope.status += "\nBytes written: " +
	stream.writeText(currentDocument.getItemValueString("subject"),
	NotesStream.EOL_CRLF);
	if (document1.hasItem("body")) {
		requestScope.status += "\nBytes written: " +
		stream.writeText(document1.getItemValue("body").firstElement());
	} else {
		requestScope.status += "\nBytes written: 0";
	}
	stream.close();
} else {
	requestScope.status = "Output file open failed";
}
This button creates a note collection from the documents in the current database and exports it to a text file as DXL.
var stream:NotesStream = session.createStream();
var filename:string = "c:\\dxl\\";
filename = filename + database.getFileName();
filename = filename.substring(0, filename.length() - 3) + "dxl";
if (stream.open(filename)) {
	if (stream.isReadOnly()) {
		requestScope.status = filename + " is read-only";
		return;
	}
	requestScope.status = "Opened " + filename;
	stream.truncate();
        
	// Create note collection
	var nc:NotesNoteCollection = database.createNoteCollection(false);
	nc.setSelectDocuments(true);
	nc.buildCollection();
        
	// Export note collection as DXL
	var exporter:NotesDxlExporter = session.createDxlExporter();
	var output:string = exporter.exportDxl(nc);
	stream.writeText(output);
	requestScope.status = "Exported note collection as DXL ";
	stream.close();
} else {
	requestScope.status = "Unable to open " + filename;
}