Load & Save

[Top]  [Chapter]  [Previous]  [Next]

 

Interface "Memo" includes methods for loading and saving data quietly:

 

bool LoadFromFile(string filename, bool Insert, string FormatStr);

bool SaveToFile(string filename, bool OnlySelection, string FormatStr);

bool LoadFromStream(object Stream, bool Insert, string FormatStr);

bool SaveToStream(object Stream, bool OnlySelection,string FormatStr);

bool LoadFromString(string Data, bool Insert, string FormatStr);

string SaveToString(bool OnlySelection, string FormatStr);

 

If the parameter "Insert" is true the text will be inserted at the current cursor position.

 

If the parameter "OnlySelection" is true only the selected text will be saved.

 

The parameter FormatStr controls the format to create or load.

 

Possible values are "AUTO" (default), "RTF", "ANSI", "HTML", "XML", "XMLTAGS" and "UNICODE".

 

RTF2PDF TextDynamic Server V4.23 and later can load and save MS Word DocX files. TextDynamic 7 can load and save in this format if the DocX license had been activated.

 

When reading text the format is detected automatically if an empty string or "AUTO" was specified.

 

"RTF" selects the RTF reader and writer. RTF is a text format standard which is widely understood.

"HTML" selects the HTML/CSS reader or writer

"XML" writes simplified HTML code. You can use "XML-useptag,-ignorefonts" to only write <p>, <b>, <i>, <u> and <a> tags. Paragraphs may use styles which are written as class="".

"XMLTAGS" is used to select a special XML reader which creates tag objects. (see: SetXMLSchema )

"ANSI" writes standard ANSI text. You can use "ANSI-codepageXXX" to write text for a certain code page

"UNICODE" reads and writes unicode (2 byte) data

 

Additional parameters are possible, such as "RTF-onlybody". (See formatstrings.htm)

 

The "Stream" parameter for LoadFromStream is an IStream or IWPStream interface. An IWPStream interface is provided by the utility class Stream2WPStream which is implemented by the c# wrapper.

 

This example loads from a file stream - the format is automatically detected.

 

 IWPMemo Memo = WPDLLInt1.Memo;

 FileStream textstream = new FileStream("C:\\1.htm",FileMode.Open);

 Memo.LoadFromStream(

            new WPDynamic.Stream2WPStream(textstream),

            false, "" );

 textstream.Close();

 

This example creates HTML code in a new file stream:

 

 IWPMemo Memo = WPDLLInt1.Memo;

 FileStream textstream = new FileStream("C:\\new.htm",FileMode.Create);

 Memo.SaveToStream(

            new WPDynamic.Stream2WPStream(textstream),

            false, "HTML" );

 textstream.Close();

 

 

 

 

When you work with a data bound editor you need to use TextCursor.CheckState(10) to trigger the PropChanged before any code which updates the text.

 


[loadsave.htm]    Copyright © 2007 by WPCubed GmbH