Reputation: 223
..\..\..\ConnectionInterface\ConnectionInterface.vbproj
I mean the "..\"
Because I am reading up a .sln file as a text file to get all the projects in that solution and the problem is this projects inside where in different directories or level.
Here is an example
..\..\..\ConnectionInterface\ConnectionInterface.vbproj
..\States\Components\States.vbproj
any ideas how to get the actual paths of these projects?
Upvotes: 1
Views: 143
Reputation: 24713
Path.GetFullPath(@"..\..\..\ConnectionInterface\ConnectionInterface.vbproj");
This is relative to the current working directory, therefore if the relative reference is not based on the current working directory you will need to define that first.
Upvotes: 2
Reputation: 1499860
You can use Path.Combine
, but you'll need to know where it's relative to. Basically find the directory that contains the original .sln file (e.g. using Path.GetDirectoryName
and Path.GetFullPath
) and then use Path.Combine
to combine the original directory with the relative file.
For example:
using System;
using System.IO;
using System.Linq;
using System.Xml.Linq;
class Test
{
static void Main()
{
string originalFile = "Test.cs";
string relative = @"..\Documents\Foo";
string originalAbsoluteFile = Path.GetFullPath(originalFile);
string originalDirectory = Path.GetDirectoryName(originalAbsoluteFile);
string combined = Path.Combine(originalDirectory, relative);
string combinedAbsolute = Path.GetFullPath(combined);
Console.WriteLine(combinedAbsolute);
}
}
Upvotes: 1
Reputation: 11155
The question isn't very clear, but if you mean does C# understand: C:\SomeDir\InnerDir1\ ..\InnerDir2 to resolve to C:\SomeDir\InnerDir2, then yes, it will work. Just append directory the solution file is in with the relative path, and you are done.
Upvotes: 1