Absolute Path from Relative Path

We have an extended property to get the path of the config file. User can enter either the absolute path of the config file or a relative path. Relative path can be just the file name indicating in the current project or a path like “..\SecondProject\myConfig.xml” indicating the file from another project in the same solution. For finding the absolute path and reading the config file, we used the EnvDTE along with methodws from Path class.

For accessing the current directory, we used the method specified in https://ambilykk.wordpress.com/2011/03/14/envdte-current-directory/

Now, convert the relative path input to absolute using

Path.GetFullPath(System.IO.Path.Combine(GetCurrentDirectoryPath(), myConfigPath))

This will work with any type of relative path like

This will work with the relative paths like

1. Path.GetFullPath(System.IO.Path.Combine(GetCurrentDirectoryPath(), “MyFile.xml”))

2. Path.GetFullPath(System.IO.Path.Combine(GetCurrentDirectoryPath(), “..\SecondProject\MyFile.xml”))

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.

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