ITextDocumentFactoryService.CreateAndLoadTextDocument Method (String, IContentType, Boolean, Boolean)

Creates an ITextDocument that opens and loads the contents of the file into a new ITextBuffer.

Namespace:  Microsoft.VisualStudio.Text
Assembly:  Microsoft.VisualStudio.Text.Data (in Microsoft.VisualStudio.Text.Data.dll)

ITextDocument CreateAndLoadTextDocument(
	string filePath,
	IContentType contentType,
	bool attemptUtf8Detection,
	out bool characterSubstitutionsOccurred
)

Parameters

filePath
Type: String

The full path to the file to be loaded.

contentType
Type: Microsoft.VisualStudio.Utilities.IContentType

The IContentType for the ITextBuffer.

attemptUtf8Detection
Type: Boolean

Whether to attempt to load the document as a UTF-8 file.

characterSubstitutionsOccurred
Type: Boolean

[out] Set to true if some of the file bytes could not be directly translated using the given encoding.

ExceptionCondition
ArgumentNullException

filePath or contentType is null.

The Visual Studio implementation of this method detects file encoding as follows:

  1. If there is a byte order mark, then use the corresponding encoding.

  2. Otherwise, iterate through the IEncodingDetector objects that match the contentType parameter until one returns a non-null Encoding value, and use that encoding.

  3. If no encoding was detected, and the attemptUtf8Detection flag is set, and the stream can be decoded as UTF8 but not ASCII, then use UTF8.

  4. Otherwise, use the system default encoding.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2015 Microsoft