ITextDocumentFactoryService::CreateAndLoadTextDocument Method (String^, IContentType^, Boolean, Boolean)
Creates an ITextDocument that opens and loads the contents of the file into a new ITextBuffer.
Assembly: Microsoft.VisualStudio.Text.Data (in Microsoft.VisualStudio.Text.Data.dll)
ITextDocument^ CreateAndLoadTextDocument( String^ filePath, IContentType^ contentType, bool attemptUtf8Detection, [OutAttribute] bool% characterSubstitutionsOccurred )
Parameters
- filePath
-
Type:
System::String^
The full path to the file to be loaded.
- contentType
-
Type:
Microsoft.VisualStudio.Utilities::IContentType^
The IContentType for the ITextBuffer.
- attemptUtf8Detection
-
Type:
System::Boolean
Whether to attempt to load the document as a UTF-8 file.
- characterSubstitutionsOccurred
-
Type:
System::Boolean
[out] Set to true if some of the file bytes could not be directly translated using the given encoding.
| Exception | Condition |
|---|---|
| ArgumentNullException | filePath or contentType is null. |
The Visual Studio implementation of this method detects file encoding as follows:
If there is a byte order mark, then use the corresponding encoding.
Otherwise, iterate through the IEncodingDetector objects that match the contentType parameter until one returns a non-null Encoding value, and use that encoding.
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.
Otherwise, use the system default encoding.