How to programmatically get the folder name where the custom project item being added to? RRS feed

  • Question

  • We created a multi-file project item, this project item contains several files and a folder, text below describes the structure of these files.

    CustomUiControl.xaml (file)

    CustomUiControl.xaml.cs (file)

    CustomUiViewModel.cs (file)

    Pages (Folder)

    ---Page1Control.xaml (file)

    ---Page1Control.xaml.cs (file)

    ---Page1ViewModel.cs (file)

    We need to use some custom replacement strings, so we create wizard that work with this template. In IWizard.RunStarted method we add some custom replacement strings into replacementsDictionary. The value of these replacement strings are created base on the user's input in 'Add New Item' dialog. For example if user input 'MyCustomUi', then we will create a replacement string '$CustomUiViewModel$' with value 'MyCustomUiViewModel'. But in the 'CustomUiViewModel.cs' file we need to create an instance of 'Page1ViewModel' , so we need to use the namespace of 'Page1ViewModel' in 'CustomUiViewModel.cs' file. But this namespace varies. So we create a replacement string ($SubViewModelNamespace$) for this namespace.  If we add our custom project item under a specified project folder (Let's say the folder name is 'MyCustomUIs'). The namespace of 'Page1ViewModel' should be ‘[project default namespace].MyCustomUIs.Pages'. But we can't get the folder that our custom project item being added to. So we can't create correct value for $SubViewModelNamespace$. Is there any way we can programatically get this folder name in IWizard.RunStarted method?


    Tuesday, February 26, 2013 10:21 AM

All replies

  • We can use dte.Project.FullName to get the full path of project. Then we can get the folder name from the path.


    • Proposed as answer by Ego Jiang Thursday, March 7, 2013 9:15 AM
    Monday, March 4, 2013 1:59 AM