Solution3.FindProjectItem Method (String)

Locates an item in a project.

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


Function FindProjectItem ( _
    FileName As String _
) As ProjectItem
ProjectItem FindProjectItem(
    string FileName
ProjectItem^ FindProjectItem(
    String^ FileName
abstract FindProjectItem : 
        FileName:string -> ProjectItem 
function FindProjectItem(
    FileName : String
) : ProjectItem


  • FileName
    Type: System.String
    Required. The name of the project item to locate.

Return Value

Type: EnvDTE.ProjectItem
A ProjectItem object.




FindProjectItem performs an OpenFile -type search for the given file name. The first project found to have the item returns its ProjectItem object for the name. If the file is not found in the solution, nulla null reference (Nothing in Visual Basic) is returned.


For information on how to run this add-in code, see How to: Compile and Run the Automation Object Model Code Examples.

Public Sub OnConnection(ByVal application As Object, _
 ByVal connectMode As ext_ConnectMode, ByVal addInInst As Object, _
 ByRef custom As Array) Implements IDTExtensibility2.OnConnection
    _applicationObject = CType(application, DTE2)
    _addInInstance = CType(addInInst, AddIn)
End Sub

Sub SolnFindProjectItemExample(ByVal dte As DTE2)
    ' This add-in finds a project item in a  solution.
    ' Make sure you have a solution open in Visual 
    ' Studio before running this example.
        Dim soln As Solution3 =  _
        CType(_applicationObject.Solution, Solution3)
        MsgBox("Finding a project item in the solution ")
        ' Find the specified project.
        Dim proj As ProjectItem
        proj = soln.FindProjectItem _
    Catch ex As System.Exception
    End Try
End Sub
using System.Windows.Forms;
public void OnConnection(object application,
 Extensibility.ext_ConnectMode connectMode, object addInInst,
 ref System.Array custom)
    _applicationObject = (DTE2)application;
    _addInInstance = (AddIn)addInInst;
    // Pass the applicationObject member variable to the code example.

public void CreateExample(DTE2 dte)
    // This add-in finds a project item in a solution.
    // Open a solution in Visual Studio before running 
    // this example.
        Solution3 soln = (Solution3)_applicationObject.Solution;
        MessageBox.Show("Finding a project item in the solution.");
        ProjectItem proj;
        proj =
        MessageBox.Show("The project item found is: " 
          + proj.Name.ToString());
    catch (SystemException ex)
        MessageBox.Show("ERROR: " + ex);

.NET Framework Security

See Also


Solution3 Interface

FindProjectItem Overload

EnvDTE90 Namespace

Other Resources

How to: Compile and Run the Automation Object Model Code Examples