This documentation is archived and is not being maintained.

Converting Between SharePoint Project System Types and Other Visual Studio Project Types

In some cases you might have an object in the SharePoint project system and you want to use features of a corresponding object in the Visual Studio automation object model or integration object model, or vice versa. In these cases, you can use the Convert<TInput, TOutput> method of the SharePoint project service to convert the object to a different object model.

For example, you might have an ISharePointProject object, but you want to use methods that are only available on an EnvDTE.Project or Microsoft.VisualStudio.Shell.Interop.IVsProject object. In this case, you can use the Convert<TInput, TOutput> method to convert the ISharePointProject to an EnvDTE.Project or Microsoft.VisualStudio.Shell.Interop.IVsProject.

For more information about the Visual Studio automation object model and the Visual Studio integration object model, see Overview of the Programming Model of SharePoint Tools Extensions.

The following table lists the types that this method can convert between the SharePoint project system and the other Visual Studio object models.

SharePoint project system type

Corresponding types in the automation and integration object models




Any interface in the Visual Studio integration object model that is implemented by the underlying COM object for the project. These interfaces include Microsoft.VisualStudio.Shell.Interop.IVsHierarchy, Microsoft.VisualStudio.Shell.Interop.IVsProject (or a derived interface), and Microsoft.VisualStudio.Shell.Interop.IVsBuildPropertyStorage. For a list of the main interfaces that are implemented by projects, see Project Model Core Components.









A UInt32 value (also called a VSITEMID) that identifies the project member in the Microsoft.VisualStudio.Shell.Interop.IVsHierarchy that contains it. This value can be passed to the itemid parameter of some Microsoft.VisualStudio.Shell.Interop.IVsHierarchy methods.

The following code example demonstrates how to use the Convert<TInput, TOutput> method to convert an ISharePointProject object to an EnvDTE.Project.

void projectService_ProjectAdded(object sender, Microsoft.VisualStudio.SharePoint.SharePointProjectEventArgs e)
    EnvDTE.Project dteProject = e.Project.ProjectService.Convert<
        Microsoft.VisualStudio.SharePoint.ISharePointProject, EnvDTE.Project>(e.Project);

    if (dteProject != null)
        // Use the Visual Studio automation object model to add a folder to the project.

This example requires: