IVsProject::AddItem Method (UInt32, VSADDITEMOPERATION, String^, UInt32, array<String^>^, IntPtr, array<VSADDRESULT>^)

 

Creates new items in a project, adds existing files to a project, or causes Add Item wizards to be run.

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

int AddItem(
	unsigned int itemidLoc,
	VSADDITEMOPERATION dwAddItemOperation,
	String^ pszItemName,
	unsigned int cFilesToOpen,
	array<String^>^ rgpszFilesToOpen,
	IntPtr hwndDlgOwner,
	array<VSADDRESULT>^ pResult
)

Parameters

itemidLoc
Type: System::UInt32

[in] Identifier of the container folder for the item being added. Should be VSITEMID_ROOT or other valid item identifier. See the enumeration VSITEMID. Note that this parameter is currently ignored because only adding items as children of a project node is supported. Projects that support the notion of folders will want to add the items relative to itemidLoc.

dwAddItemOperation
Type: Microsoft.VisualStudio.Shell.Interop::VSADDITEMOPERATION

[in] Operation applied to the newly created item. See the enumeration VSADDITEMOPERATION.

pszItemName
Type: System::String^

[in] Name of the item to be added.

cFilesToOpen
Type: System::UInt32

[in] Number of items in rgpszFilesToOpen. Can be zero. This must be 1 if dwAddItemOperation is VSADDITEMOP_CLONEFILE or VSADDITEMOP_OPENDIRECTORY. If VSADDITEMOP_RUNWIZARD, it must be 1 or 2.

rgpszFilesToOpen
Type: array<System::String^>^

[in, size_is(cFilesToOpen)] Array of pointers to OLESTR file names. If dwAddItemOperation is VSADDITEMOP_CLONEFILE or VSADDITEMOP_OPENDIRECTORY, the first item (rgpszFilesToOpen[0]) in the array is the name of the file to clone or the directory to open. If it is VSADDITEMOP_RUNWIZARD, the first item (rgpszFilesToOpen[0]) is the name of the wizard to run, and the second item (rgpszFilesToOpen[1]) is the file name the user supplied (same as pszItemName).

hwndDlgOwner
Type: System::IntPtr

[in] Handle to the Add Item dialog box.

pResult
Type: array<Microsoft.VisualStudio.Shell.Interop::VSADDRESULT>^

[out, retval] Pointer to the VSADDRESULT enumeration indicating whether the item was successfully added to the project.

Return Value

Type: System::Int32

If the method succeeds, it returns S_OK. If it fails, it returns an error code.

From vsshell.idl:

HRESULT IVsProject::AddItem(
   [in] VSITEMID itemidLoc,
   [in] VSADDITEMOPERATION dwAddItemOperation,
   [in] LPCOLESTR pszItemName,
   [in] ULONG cFilesToOpen,
   [in, size_is(cFilesToOpen)] LPCOLESTR rgpszFilesToOpen[],
   [in] HWND hwndDlgOwner,
   [out, retval] VSADDRESULT * pResult
);

This method is used by the Add Item dialog box. The method can create new items, add existing files, or cause Add Item wizards to be run.

This method should only be called from within the UI thread, otherwise it will throw a COMException.

Return to top
Show: