Share via


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)

Syntax

'Declaration
Function CreateAndLoadTextDocument ( _
    filePath As String, _
    contentType As IContentType, _
    attemptUtf8Detection As Boolean, _
    <OutAttribute> ByRef characterSubstitutionsOccurred As Boolean _
) As ITextDocument
ITextDocument CreateAndLoadTextDocument(
    string filePath,
    IContentType contentType,
    bool attemptUtf8Detection,
    out bool characterSubstitutionsOccurred
)
ITextDocument^ CreateAndLoadTextDocument(
    String^ filePath, 
    IContentType^ contentType, 
    bool attemptUtf8Detection, 
    [OutAttribute] bool% characterSubstitutionsOccurred
)
abstract CreateAndLoadTextDocument : 
        filePath:string * 
        contentType:IContentType * 
        attemptUtf8Detection:bool * 
        characterSubstitutionsOccurred:bool byref -> ITextDocument
function CreateAndLoadTextDocument(
    filePath : String, 
    contentType : IContentType, 
    attemptUtf8Detection : boolean, 
    characterSubstitutionsOccurred : boolean
) : ITextDocument

Parameters

  • filePath
    Type: System.String

    The full path to the file to be loaded.

  • 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.

Return Value

Type: Microsoft.VisualStudio.Text.ITextDocument
The ITextDocument.

Exceptions

Exception Condition
ArgumentNullException

filePath or contentType is nulla null reference (Nothing in Visual Basic).

Remarks

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.

.NET Framework Security

See Also

Reference

ITextDocumentFactoryService Interface

CreateAndLoadTextDocument Overload

Microsoft.VisualStudio.Text Namespace