Save Method
Collapse the table of content
Expand the table of content

Project.Save Method

Saves the project or project item.

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

void Save(
	string FileName


Type: System.String
Optional. The name in which to save the project or project item.

If FileName cannot be written, such as when the disk is full or when there are write permission problems, then Save produces an error. The file is saved with a new name based on FileName.

Important   Save closes the document after it is saved. The object will need to be re-opened or re-initialized if it is used again.

This example works only in Visual Studio .NET 2003 and later versions. For more information, see How to: Programmatically Create Projects.

public void SaveExample(DTE dte)
    // NOTE: This example requires a reference to the 
    //       VSLangProj namespace.

    // Create a new solution.
    Solution soln = dte.Solution;
    string solnName = "NewSolution.sln";
    string tempPath = System.IO.Path.GetTempPath();
    soln.Create(tempPath, solnName);

    // Create a new C# Console Application project.
    string templatePath = 
    templatePath += "CSharpConsole.vsz";
    string projName = "NewProject";
    soln.AddFromTemplate(templatePath, tempPath + projName, 
        projName, false);
    Project proj = soln.Item(1);

    // Add a new class to the project.
    templatePath = dte.Solution.ProjectItemsTemplatePath(
    templatePath += @"\CSharpAddClassWiz.vsz";
    string projItemName = "NewClass.cs";
    ProjectItem projItem = proj.ProjectItems.AddFromTemplate(
        templatePath, projItemName);

    // Add a using statement to the class file.
    TextSelection sel = (TextSelection)projItem.Document.Selection;
    sel.Insert("using System.Collections;" + Environment.NewLine, 

    // Save the project item, project, and solution.
    soln.SaveAs(tempPath + solnName);

Community Additions

© 2016 Microsoft