Export (0) Print
Expand All

Project.Save Method

Saves the project or project item.

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

void Save(
	string FileName
)

Parameters

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 = 
        dte.Solution.get_TemplatePath(PrjKind.prjKindCSharpProject);
    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(
        PrjKind.prjKindCSharpProject);
    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.StartOfDocument(false);
    sel.Insert("using System.Collections;" + Environment.NewLine, 
        (int)vsInsertFlags.vsInsertFlagsCollapseToStart);

    // Save the project item, project, and solution.
    projItem.Save("");
    proj.Save(proj.FullName);
    soln.SaveAs(tempPath + solnName);
}

Community Additions

ADD
Show:
© 2014 Microsoft