Paste Method
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer

TextSelection.Paste Method

Inserts the clipboard contents at the current location.

Namespace: EnvDTE
Assembly: EnvDTE (in envdte.dll)

void Paste ()
void Paste ()
function Paste ()

Paste moves the edit point past the insertion.

public void PasteExample(DTE2 dte)
    // Create a new text file and insert ten lines of text.
    dte.ItemOperations.NewFile(@"General\Text File", "", 
    TextDocument textDoc = 
    EditPoint editPnt = textDoc.StartPoint.CreateEditPoint();
    for (int i = 1; i <= 10; i++)
        editPnt.Insert("Line " + i.ToString() + "\n");

    if (MessageBox.Show("Reverse the order of the lines?", "", 
        MessageBoxButtons.YesNo) == DialogResult.Yes)
        TextSelection textSel = textDoc.Selection;

        // Position insertion point at beginning of "Line 2".
        textSel.LineDown(false, 1);

        // Reverse the order of the lines by cutting "Line 2" and
        // pasting it at the start of the document, and then cutting
        // "Line 3" and pasting it at the start of the document,
        // and so on.
        for (int i = 1; i <= 9; i++)
            textSel.LineDown(true, 1);
© 2015 Microsoft