Version

Configuring Initial Content (xamSyntaxEditor)

Topic Overview

Purpose

In this topic, you will find instructions and code examples for using the xamSyntaxEditor™ TextDocument's Load and Save methods for loading and saving content.

Required background

The following topics are prerequisites to understanding this topic:

Topic Purpose

In this topic, you will find information to help you better understand the xamSyntaxEditor’s functions.

This topic provides you with systematic instructions designed to help you get the xamSyntaxEditor up and running as quickly as possible.

Prerequisites

To complete the procedure, you need the following:

Note
Note

It is important to configure the Document property prior to loading its content as some languages, Visual Basic for one, can modify a keyword’s case. To apply the correct syntax highlighting, set the TextDocument’s language.

Please refer to the Syntax Highlighting topic for additional information about configuring document languages.

Document Loading and Saving Summary

Document loading methods

The following table lists the methods available to you for loading and saving TextD``ocument content.

Configurable aspects Details

Loads the document’s content from the file location that you specify and provide as a string.

Loads the document’s content from the stream you provide.

Loads the document’s content from the string that you provide.

Saves the document’s content to the file location that you specify and provide as a string.

Saves the document’s content to the stream you provide.

Loading document from a file location

Overview

This method allows you to load a specific file by passing its location as a string value.

Methods

In order to: Invoke this method: And provide:

Load content in the TextDocument

file’s location, as a string

Example

In C#:

this.xamSyntaxEditor1.Document.Load("C:\\file.txt");

In Visual Basic:

Me.xamSyntaxEditor1.Document.Load("C:\file.txt")

Loading document from a stream

Overview

This method allows you to load document content from the stream you specify.

Methods

In order to: Invoke this method: And provide:

Load content in the TextDocument

stream containing the text content

Example

In C#:

FileInfo fi = new FileInfo("C:\\file.txt");
FileStream fs = fi.OpenRead();
this.xamSyntaxEditor1.Document.Load(fs);

In Visual Basic:

Dim fi As New FileInfo("C:\file.txt")
Dim fs As FileStream = fi.OpenRead()
Me.xamSyntaxEditor1.Document.Load(fs)

Loading document by providing the content as a string

Overview

This method allows you to load a document’s content from a string value you specify.

Methods

In order to: Invoke this method: And provide:

Load content in the TextDocument

content as string

Example

In C#:

this.xamSyntaxEditor1.Document.InitializeText("the quick brown fox... ");

In Visual Basic:

Me.xamSyntaxEditor1.Document.InitializeText("the quick brown fox...")

Saving document to a file location

Overview

This method allows you to save a document’s content to a specific file by passing its location as a string value.

Saves the document’s content to the file location, which you provide as string.

Methods

In order to: Invoke this method: And provide:

Save the TextDocument’s content to a file

file location as string

Example

In C#:

this.xamSyntaxEditor1.Document.Save("C:\\file.txt");

In Visual Basic:

Me.xamSyntaxEditor1.Document.Save("C:\file.txt")

Saving document to a stream

Overview

This method allows you to save a document to the stream you specify.

Methods

In order to: Invoke this method: And provide:

Save the TextDocument’s content in a stream

stream to which the content is saved

Example

In C#:

FileInfo fi = new FileInfo("C:\\file.txt");
FileStream fs = fi.OpenWrite();
this.xamSyntaxEditor1.Document.Save(fs);

In Visual Basic:

Dim fi As New FileInfo("C:\file.txt")
Dim fs As FileStream = fi.OpenWrite()
Me.xamSyntaxEditor1.Document.Save(fs)

Related Topics

The following topics provide additional information related to this topic.

Topic Purpose

This topic provides information about text colorization, based on the TextDocument’s associated language.