EditPoint2.InsertFromFile(String) 方法

定義

在緩衝區中的目前位置插入指定檔案的內容。Inserts the contents of the specified file at the current location in the buffer.

public:
 void InsertFromFile(System::String ^ File);
public:
 void InsertFromFile(Platform::String ^ File);
void InsertFromFile(std::wstring const & File);
[System.Runtime.InteropServices.DispId(133)]
public void InsertFromFile (string File);
[<System.Runtime.InteropServices.DispId(133)>]
abstract member InsertFromFile : string -> unit
Public Sub InsertFromFile (File As String)

參數

File
String

必要。Required. 要插入到文字緩衝區的檔案名稱。The name of the file to insert into the text buffer.

實作

屬性

範例

Sub InsertFromFileExample(ByVal dte As DTE2)  

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

    ' Create a new text file and insert ten 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 ten 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);  
    }  
}  

備註

編輯點會移動超過插入點。The edit point moves past the insertion point. 文字會轉換成 Unicode,也就是文字檔所使用的內部標記法。The text is converted to Unicode, which is the internal representation used by text documents.

適用於