EnvDTE Current Directory

Most of the time, we may be adding few extenders to our windows application to deal with various requirements. One of our requirement is to get the current directory path to the extender and display the extended property value accordingly.

For accessing the current directory path, we used the EnvDTE.

public string GetCurrentDirectoryPath()
 {
 Project currentProject = null;
 DTE dte = this.GetService(typeof(EnvDTE.DTE)) as EnvDTE.DTE; 
if (dte == null) 
return null; 
if (dte.ActiveDocument != null &&dte.ActiveDocument.ActiveWindow !=null &&dte.ActiveDocument.ActiveWindow.Project !=null )
{
currentProject = dte.ActiveDocument.ActiveWindow.Project;
}  
else
{
Array solutions = dte.ActiveSolutionProjects; 
string projectAssemblyName = string .Empty; 
if (solutions.Length > 0)
{
currentProject = solutions.GetValue(0) as Project ;
}
string path = System.IO.Path .GetDirectoryName(currentProject.FullName); 
return path;
}

 

 

Advertisements

About ambilykk

I am a Technology Evangelist on Microsoft Technologies. I am carrying the passion on Microsoft technologies specifically on web technologies such as ASP .Net and Ajax. My interests also include Azure and Visual Studio. Technology adoption and learning is my key strength and technology sharing is my passion.
This entry was posted in C#, EnvDTE and tagged , . Bookmark the permalink.

2 Responses to EnvDTE Current Directory

  1. Pingback: Absolute Path from Relative Path | Ambilykk's Blog

  2. Pingback: Absolute Path from Relative Path | ASP.NET tutorials for beginners

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s