We recommend using Visual Studio 2017
This documentation is archived and is not being maintained.

IVsProject2.GenerateUniqueItemName Method

Generates a unique document name for a given item.

Namespace:  Microsoft.VisualStudio.Shell.Interop
Assembly:  Microsoft.VisualStudio.Shell.Interop (in Microsoft.VisualStudio.Shell.Interop.dll)

int GenerateUniqueItemName(
	uint itemidLoc,
	string pszExt,
	string pszSuggestedRoot,
	out string pbstrItemName


Type: System.UInt32

[in] Container folder for the unique item name being generated. Should be a valid item identifier. For further information, see VSITEMID. The value of this parameter is typically determined by the itemidLoc parameter that the project passes to the AddProjectItemDlg method.

Type: System.String

[in] File extension of the new document name.

Type: System.String

[in] If not null or empty, this value should be used as the base name for the item, and numbers should be appended to make the name unique. If supplied, the project should make up its own root name based on the pszExt file extension.

Type: System.String

[out] Pointer to the new name, which contains the name only, not the item's file path.

Return Value

Type: System.Int32
If the method succeeds, it returns S_OK. If it fails, it returns an error code.

COM Signature

From vsshell.idl:

HRESULT IVsProject2::GenerateUniqueItemName(
   [in] VSITEMID itemidLoc,
   [in] LPCOLESTR pszExt,
   [in] LPCOLESTR pszSuggestedRoot,
   [out] BSTR * pbstrItemName

The Add Item dialog box uses this method to suggest a name for the user when a new item is selected.