Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Find the solution directory during design-time?

Status
Not open for further replies.

CrashDome

Technical User
Jan 7, 2002
86
US
I am completely unfamiliar with how to retrieve the current solution's directory via code?

My custom UITypeEditor is perfect except that the values I want to select are dynamically stored in an XML document with the solution and NOT like an enumeration or value placed within the DLL.

So if I open "MySolution" the UITypeEditor should access or create an XML document within "MySolution" directory.

How do I do this?

 
Found it... Man that was some hard searching though.

You would figure it would be under a "Get Solution Directory" search on MSDN or something that simple... but rather I had to search for design time environment and then go from there until I got to "Referencing Automation Assembly"...

Never would have guessed that!!!!

Anyways, the solution for VS 2005 is:

Reference EnvDTE and EnvDTE80 in project and in code do this:
Code:
using EnvDTE;
using EnvDTE80;

...
...
...

public class MyClass
{
   private EnvDTE80.DTE2 dte2;
   private Solution2 soln;

   public MyClass()
   {
      dte2 = (EnvDTE80.DTE2)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.8.0");

      soln = (Solution2)dte2.Solution;

      MessageBox.Show("My Solution Directory is: "+soln.Fullname)
   }
}

My guess is that VS 2003 is same except use only EnvDTE and get rid of all the '2's at the end of all the objects and find the appropriate VisualStudio.DTE version to put in GetActiveObject method. (I dont know what it would be)

Yay me for answering my own question!
 
You can also just use (at least in VS2003) Environment.CurrentDirectory, which returns the place that you are executing from, which is where your items should be relative to, anyway, not where your solution file is.

You can get more information here

----------------------------------------

TWljcm8kb2Z0J3MgIzEgRmFuIQ==
 
I believe that returns the path to the Visual Studio directory in my case. Not exactly what I am looking for specifically. I wanted the path to the solution's directory.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top