Freigeben über


SolutionFolder.Parent Property

Definition

Gets the immediate parent object of a Find object.

public:
 property EnvDTE::Project ^ Parent { EnvDTE::Project ^ get(); };
public:
 property EnvDTE::Project ^ Parent { EnvDTE::Project ^ get(); };
[System.Runtime.InteropServices.DispId(2)]
public EnvDTE.Project Parent { [System.Runtime.InteropServices.DispId(2)] get; }
[<System.Runtime.InteropServices.DispId(2)>]
[<get: System.Runtime.InteropServices.DispId(2)>]
member this.Parent : EnvDTE.Project
Public ReadOnly Property Parent As Project

Property Value

A DTE object.

Attributes

Examples

This example creates a new solution folder and adds a project to it from an existing file. It then uses a message box to display all the project items in the solution folder, obtained through the Parent object. Before running this example, create a "Projects" folder off your main drive ("C:" in this example), and create a Visual C# class library project, named "ClassLibrary1" in that folder. You need to also open a project in the Visual Studio integrated development environment (IDE) before running this example.

Imports EnvDTE  
Imports EnvDTE80  
Sub solnFolderParentExample(ByVal dte As DTE2)  
    ' Before running this example, create a "Projects" folder  
    ' off your main drive (C: in this example), and create a C#   
    ' class library project, named ClassLibrary1 in that folder.  
    Dim soln As Solution2 = CType(_applicationObject.Solution _  
    , Solution2)  
    Dim prj As Project  
    Dim sb As New System.Text.StringBuilder  
    Dim SF As SolutionFolder  
    Try  
        Dim prjPath As String = _  
         "C:\Projects\ClassLibrary1\ClassLibrary1\ClassLibrary1.csproj"  
        ' Open a project in the Visual Studio IDE before   
        ' running this example.  
        ' Add a solution folder.  
        prj = soln.AddSolutionFolder("A new soln folder")  
        SF = CType(prj.Object, SolutionFolder)  
        ' Add a project to the new solution folder.  
        SF.AddFromFile(prjPath)  
        MsgBox("Added a new solution folder that contains a _  
        C# project named ClassLibrary1.")  
        MsgBox("The name of the solution folder parent is: "  _  
        & SF.Parent.Name)  
        Dim tempStr As String  
        tempStr = ""  
        For Each temp As ProjectItem In SF.Parent.ProjectItems  
            tempStr = tempStr & temp.Name & vbCr  
        Next  
        MsgBox("The names of the project items in the solution _  
        folder SF are:" & vbCr & tempStr)  
    Catch ex As System.Exception  
        MsgBox(ex.ToString)  
    End Try  
End Sub  
using EnvDTE;  
using EnvDTE80;  
using System.Windows.Forms;  
public void solnFolderParentExample(DTE2 dte)  
{  
    // Before running this example, create a "Projects" folder  
    // off your main drive (C: in this example), and create a C#   
    // class library project, named ClassLibrary1 in that folder.  
    Solution2 soln = (Solution2)_applicationObject.Solution;  
    Project prj;  
    SolutionFolder SF;  
    try  
    {  
        String prjPath =  
 "C:\\Projects\\ClassLibrary1\\ClassLibrary1\\ClassLibrary1.csproj";  
        // Open a project in the Visual Studio IDE before   
        // running this example.  
        // Add a solution folder.  
        prj = soln.AddSolutionFolder("A new soln folder");  
        SF = (SolutionFolder)prj.Object;  
        // Add a project to the new solution folder.  
        SF.AddFromFile(prjPath);  
        MessageBox.Show("Added a new solution folder that contains a   
C# project named ClassLibrary1.");  
        MessageBox.Show("The name of the solution folder parent is: "   
+ SF.Parent.Name);  
        String tempStr = null;  
        foreach(ProjectItem temp in SF.Parent.ProjectItems)  
        {  
            tempStr = tempStr + temp.Name + "\n";  
        }  
        MessageBox.Show("The names of the project items in the   
solution folder SF are:" + "\n" + tempStr);  
    }  
    catch(SystemException ex)  
    {  
        MessageBox.Show(ex.ToString());  
    }  
}  

Remarks

The Parent property returns the immediate parent to the Find object.

Applies to