This documentation is archived and is not being maintained.

Document.Close Method

Closes the open document and optionally saves it, or closes and destroys the window.

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

void Close(
	vsSaveChanges Save
)

Parameters

Save
Type: EnvDTE.vsSaveChanges

Optional. A vsSaveChanges constant that determines whether to save an item or items.

public void CloseExample(DTE2 dte)
{
    // NOTE: This example requires a reference to the 
    // System.Collections namespace.

    if (MessageBox.Show("Close all saved documents?", "", 
        MessageBoxButtons.YesNo) == DialogResult.Yes)
    {
        // Create a list of all saved documents.
        Documents docs = dte.Documents;
        ArrayList savedDocs = new ArrayList();

        for (int i = 1; i <= docs.Count; i++)
        {
            if (docs.Item(i).Saved)
                savedDocs.Add(docs.Item(i));
        }

        // Close all saved documents.
        foreach (Document doc in savedDocs)
        {
        doc.Close(vsSaveChanges.vsSaveChangesNo);
        }
    }
}

Show: