VSProject.GetUniqueFilename(Object, String, String) Method


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

 System::String ^ GetUniqueFilename(System::Object ^ pDispatch, System::String ^ bstrRoot, System::String ^ bstrDesiredExt);
 Platform::String ^ GetUniqueFilename(Platform::Object ^ pDispatch, Platform::String ^ bstrRoot, Platform::String ^ bstrDesiredExt);
std::wstring GetUniqueFilename(winrt::Windows::Foundation::IInspectable const & pDispatch, std::wstring const & bstrRoot, std::wstring const & bstrDesiredExt);
public string GetUniqueFilename (object pDispatch, string bstrRoot, string bstrDesiredExt);
abstract member GetUniqueFilename : obj * string * string -> string
Public Function GetUniqueFilename (pDispatch As Object, bstrRoot As String, bstrDesiredExt As String) As String



The name generated will have this value as the extension.


A Project object or a folder ProjectItem object. The file name generated will be unique within this context.


The name generated will start with this 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).



[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  


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.

Applies to