VSProject.GetUniqueFilename Method

Generates a unique file name within the project. Used for naming new project items.

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

Syntax

'Declaration
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

Parameters

  • pDispatch
    Type: System.Object
    The name generated will have this value as the extension.
  • bstrDesiredExt
    Type: System.String
    The name generated will start with this string.

Return Value

Type: System.String
A file name that is unique in the project or project folder. If the first parameter is a Project instance, then the name generated will be unique within the root project folder. The file name will take the form Root?.Extension, where ? is one or more numerals (1, 2, 3, and so on).

Remarks

A typical use for this method is to generate a name for a new project item.

If you call this method with KeyFile as the root and snk as the extension, the string returned is KeyFile.snk, if the file KeyFile.snk does not already exist. If the file KeyFile.snk already exists, then KeyFile1.snk is returned. Note that if multiple calls are made to this method, and no file is created from the returned file name, all the calls will return the same value. The results depend only on the files that exist at the time of the method call.

Examples

[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 Security

See Also

Reference

VSProject Interface

VSLangProj Namespace