次の方法で共有


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
    型: System.String
    必ず指定します。テキスト バッファーに挿入するファイル名。

解説

エディット ポイントはカーソル位置の後ろに移動します。 テキストは、Unicode (テキスト ドキュメントで使用される内部表現) に変換されます。

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 名前空間

その他の技術情報

方法 : オートメーション オブジェクト モデルのコード例をコンパイルおよび実行する