VSProject.GetUniqueFilename 方法

在專案內產生唯一的檔名。 用來命名新專案項目。

命名空間:  VSLangProj
組件:  VSLangProj (在 VSLangProj.dll 中)

語法

'宣告
Function GetUniqueFilename ( _
    pDispatch As Object, _
    bstrRoot As String, _
    bstrDesiredExt As String _
) As String
string GetUniqueFilename(
    Object pDispatch,
    string bstrRoot,
    string bstrDesiredExt
)
String^ GetUniqueFilename(
    [InAttribute] Object^ pDispatch, 
    [InAttribute] String^ bstrRoot, 
    [InAttribute] String^ bstrDesiredExt
)
abstract GetUniqueFilename : 
        pDispatch:Object * 
        bstrRoot:string * 
        bstrDesiredExt:string -> string 
function GetUniqueFilename(
    pDispatch : Object, 
    bstrRoot : String, 
    bstrDesiredExt : String
) : String

參數

  • pDispatch
    型別:System.Object
    產生的檔名將以這個值當做副檔名。
  • bstrDesiredExt
    型別:System.String
    產生的檔名將以這個字串開頭。

傳回值

型別:System.String
檔名,是專案或專案資料夾中唯一的檔名。如果第一個參數是 Project 執行個體,則產生的檔名在根專案資料夾內的就不會與其他檔名重複。這個檔案名稱的格式為 Root?.Extension,其中 ? 為一個或多個數字 (1、2、3 依此類推)。

備註

這個方法的典型用法是產生新專案項目的名稱。

如果您使用 KeyFile 做為根和 snk 做為副檔名來呼叫這個方法,並且如果 KeyFile.snk 檔尚未存在,則傳回的字串為 KeyFile.snk。 如果 KeyFile.snk 檔已存在,則傳回的字串為 KeyFile1.snk。 請注意,如果對這個方法進行多次呼叫,則不會從傳回的檔名來建立檔案,所有的呼叫都將傳回相同值。 結果僅取決於呼叫方法時存在的檔案。

範例

[Visual Basic]

' This macro displays a file name that is unique in the 
' project folder, in the form root?.ext.
' Macro editor
Imports VSLangProj
Imports VSLangProj80
Sub GetUniqueName()
   Dim proj As Project
   proj = DTE.Solution.Projects.Item(1)
   Dim vsproj As VSLangProj.VSProject = _
      CType(proj.Object, VSLangProj.VSProject)
   MsgBox(vsproj.GetUniqueFilename(proj, "Root", "ext"))
End Sub

.NET Framework 安全性

請參閱

參考

VSProject 介面

VSLangProj 命名空間