EditPoint.InsertFromFile 메서드

지정한 파일 내용을 버퍼의 현재 위치에 삽입합니다.

네임스페이스:  EnvDTE
어셈블리:  EnvDTE(EnvDTE.dll)

구문

‘선언
Sub InsertFromFile ( _
    File As String _
)
void InsertFromFile(
    string File
)
void InsertFromFile(
    [InAttribute] String^ File
)
abstract InsertFromFile : 
        File:string -> unit
function InsertFromFile(
    File : String
)

매개 변수

  • File
    형식: String

    필수 요소. 텍스트 버퍼에 삽입할 파일의 이름입니다.

설명

편집 지점이 삽입 지점을 지나서 이동합니다. 텍스트는 텍스트 문서에서 사용되는 내부 표현인 유니코드로 변환됩니다.

예제

Sub InsertFromFileExample(ByVal dte As DTE2)

    ' NOTE: This example requires a reference to the
    '       System.IO namespace.

    ' Create a new text file and insert 10 lines of text.
    dte.ItemOperations.NewFile(, "File1")
    Dim doc As Document = dte.ActiveDocument
    Dim sel As TextSelection = CType(doc.Selection, TextSelection)
    Dim i As Integer

    For i = 1 To 10
        sel.Insert("This is a test." & vbCrLf)
    Next i

    MsgBox("Saving and closing File1")

    ' Save and close the text file.
    Dim file1 As String = Path.GetTempPath & "File1.txt"
    doc.Save(file1)
    doc.Close()

    ' Create a new text file.
    dte.ItemOperations.NewFile(, "File2")
    doc = dte.ActiveDocument

    If MsgBox("Insert text from File1 into File2?", _
        MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
        sel = CType(doc.Selection, TextSelection)
        sel.InsertFromFile(file1)
    End If

End Sub
public void InsertFromFileExample(DTE2 dte)
{
    // NOTE: This example requires a reference to the
    //       System.IO namespace.

    // Create a new text file and insert 10 lines of text.
    dte.ItemOperations.NewFile(@"General\Text File", "File1", 
        Constants.vsViewKindPrimary);
    Document doc = dte.ActiveDocument;
    TextSelection sel = (TextSelection)doc.Selection;

    for (int i = 0; i < 10; ++i)
        sel.Insert("This is a test.\n", 
           (int)vsInsertFlags.vsInsertFlagsCollapseToEnd);

    MessageBox.Show("Saving and closing File1");

    // Save and close the text file.
    string file1 = Path.GetTempPath() + "File1.txt";
    doc.Save(file1);
    doc.Close(vsSaveChanges.vsSaveChangesNo);

    // Create a new text file.
    dte.ItemOperations.NewFile(@"General\Text File", "File2", 
        Constants.vsViewKindPrimary);
    doc = dte.ActiveDocument;

    if (MessageBox.Show("Insert text from File1 into File2?", "", 
        MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        sel = (TextSelection)doc.Selection;
        sel.InsertFromFile(file1);
    }
}

.NET Framework 보안

참고 항목

참조

EditPoint 인터페이스

EnvDTE 네임스페이스

기타 리소스

방법: 자동화 개체 모델 코드의 예제 컴파일 및 실행