Solution3.SaveAs 方法
保存解决方案。
命名空间: EnvDTE90
程序集: EnvDTE90(在 EnvDTE90.dll 中)
语法
声明
Sub SaveAs ( _
FileName As String _
)
void SaveAs(
string FileName
)
void SaveAs(
[InAttribute] String^ FileName
)
abstract SaveAs :
FileName:string -> unit
function SaveAs(
FileName : String
)
参数
FileName
类型:String必需。 用于保存解决方案的文件名。 若该文件存在,则将其覆盖。
备注
SaveAs 以指定的文件名保存解决方案。
示例
有关如何运行此外接程序代码的信息,请参见如何:编译和运行自动化对象模型代码示例。
Public Sub OnConnection(ByVal application As Object, _
ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
ByRef custom As Array) Implements IDTExtensibility2.OnConnection
_applicationObject = CType(application, DTE2)
_addInInstance = CType(addInInst, AddIn)
SaveAsExample(_applicationObject)
End Sub
Sub SaveAsExample(ByVal dte As DTE2)
' This add-in creates a solution and then saves it.
' Create the full path to NewSolution.sln.
Dim tempPath As String = System.IO.Path.GetTempPath()
Dim solnName As String = "NewSolution"
Dim solnPath As String = tempPath & solnName & ".sln"
Dim soln As Solution2 = _
CType(_applicationObject.Solution, Solution2)
Try
If MsgBox("Solution " & solnPath & " doesn't exist. " & _
"Create it?", MsgBoxStyle.YesNo) = MsgBoxResult.Yes Then
' Create and save NewSolution.sln.
dte.Solution.Create(tempPath, solnName)
dte.Solution.SaveAs(solnPath)
End If
Catch ex As SystemException
MsgBox("ERROR: " & ex.ToString())
End Try
End Sub
using System.Windows.Forms;
public void OnConnection(object application,
Extensibility.ext_ConnectMode connectMode, object addInInst,
ref System.Array custom)
{
_applicationObject = (DTE2)application;
_addInInstance = (AddIn)addInInst;
// Pass the applicationObject member variable to the code example.
SolnSaveAsExample((DTE2)_applicationObject);
}
public void SolnSaveAsExample(DTE2 dte)
{
// This add-in creates a solution and saves it.
string tempPath = System.IO.Path.GetTempPath();
string solnName = "NewSolution";
string solnPath = tempPath + solnName + ".sln";
Solution2 soln = (Solution2)_applicationObject.Solution;
try
{
if (MessageBox.Show("Solution " + solnPath +
" doesn't exist. " + "Create it?", "",
MessageBoxButtons.YesNo) == DialogResult.Yes)
{
// Create and save NewSolution.sln.
dte.Solution.Create(tempPath, solnName);
dte.Solution.SaveAs(solnPath);
}
}
catch (SystemException ex)
{
MessageBox.Show("ERROR: " + ex);
}
}
.NET Framework 安全性
- 对直接调用方的完全信任。此成员不能由部分信任的代码使用。有关详细信息,请参阅通过部分受信任的代码使用库。