How to create file associates in the Solution Explorer?

For example when you have a file of type Default.aspx and Default.cs it would make a tree branch type of architecture.

I'd like to add a .js file for example and have that file put into the branch that the solution explorer creates for the aspx file and it's code behind.

Thanks,



Answer this question

How to create file associates in the Solution Explorer?

  • Gyea

    Hello Darren,

    Assuming you control the addition of that file to the project, getting the EnvDTE.ProjectItem for the parent node and adding the child node to it's EnvDTE.ProjectItems to it should do that.

    Rusty


  • JerryHerrera

    The project controls which files are related, you cannot arbitrarily group one file underneath another (unless you created the project).

    Craig



  • Mashhood

    Hi,

    That code works great for me too, thanks...
    I'd like to have an option to nest / unnest the files under .cs files and so I'm looking for a way to do the reverse operation. Can anyone help me out

    Thanks

  • Jonathan Hseu

    Actually, after a little investigation (and having it pointed out to me that I could be wrong), we looked at it a little closer. You can do this programmatically, but with a few restrictions.

    If you run macro code like this:

    Sub nested()
    Dim pi As ProjectItem
    pi = DTE.Solution.Projects.Item(1).ProjectItems.Item("Form1.cs")
    pi.ProjectItems.AddFromFile("SomePath\TextFile1.txt")
    End Sub

    and the file TextFile1.txt is in the same directory as Form1.cs then it will work correctly and TextFile1.txt will be nested underneath Form1.cs. However, if the file is not in the same directory as Form1.cs, then a shortcut link will be created at the same level as Form1.cs and will not be nested.

    Craig



  • How to create file associates in the Solution Explorer?