Project.SaveAs 方法

更新:2007 年 11 月

保存解决方案、项目或项目项。

命名空间:  EnvDTE
程序集:  EnvDTE(在 EnvDTE.dll 中)

语法

声明
Sub SaveAs ( _
    NewFileName As String _
)
用法
Dim instance As Project
Dim NewFileName As String

instance.SaveAs(NewFileName)
void SaveAs(
    string NewFileName
)
void SaveAs(
    [InAttribute] String^ NewFileName
)
function SaveAs(
    NewFileName : String
)

参数

  • NewFileName
    类型:System.String

    必需。保存解决方案、项目或项目项所用的文件名。若该文件存在,则将其覆盖。

备注

SaveAs 以指定的文件名保存项目项。

示例

Public Sub CodeExample(ByVal dte As DTE2) 
    Try
        ' Open a project before running this sample.
        Dim prj As Project = dte.Solution.Projects.Item(1)
        Dim prjs As Projects
        
        Dim del As DialogResult
        del = MessageBox.Show("Delete project from solution?", "Delete Method", MessageBoxButtons.YesNo, MessageBoxIcon.Warning)
        If del = DialogResult.Yes Then
            prj.Delete()
        End If
        del = MessageBox.Show("Save project as another filename?", "SaveAs Method", MessageBoxButtons.YesNo)
        If del = DialogResult.Yes Then
            prj.SaveAs(Interaction.InputBox("Save this project with new name: ", "SaveAs Method", "MyProjectWithNewName", 300, 300))
        End If
    Catch ex As Exception
        MessageBox.Show(ex.Message)
    End Try
End Sub

[C#]

public void CodeExample(DTE2 dte)
{  
    try
    {   // Open a project before running this sample.
        Project prj = dte.Solution.Projects.Item(1);
        Projects prjs;

        DialogResult del;
        del = MessageBox.Show("Delete project from solution?", "Delete Method", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
        if (del == DialogResult.Yes)
            prj.Delete();
        del = MessageBox.Show("Save project as another filename?", "SaveAs Method", MessageBoxButtons.YesNo);
        if (del == DialogResult.Yes)
        {
            prj.SaveAs(Interaction.InputBox("Save this project with new name: ", "SaveAs Method",
                "MyProjectWithNewName", 300, 300));
        }
    }
    catch(Exception ex)
    {
        MessageBox.Show(ex.Message);
    }
}

权限

另请参见

参考

Project 接口

Project 成员

EnvDTE 命名空间

其他资源

如何:编译和运行自动化对象模型代码示例