Solution2.SaveAs 方法 (String)
儲存方案。
命名空間: EnvDTE80
組件: EnvDTE80 (在 EnvDTE80.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
型別:System.String
必要項。用以儲存方案的檔案名稱。如果檔案已存在,則會覆寫上去。
備註
SaveAs 會以指定之檔案名稱儲存方案。
範例
如需如何執行增益集程式碼的詳細資訊,請參閱 HOW TO:編譯和執行 Automation 物件模型程式碼範例。
下列範例示範如何建立並儲存方案。
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 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。