Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i go back a level when specifying a path in C#?

Tags:

c#

path

wix

I want to programmatically install a folder in Visual Studio's "Extensions" folder. The closest i can get is using the VS100COMNTOOLS environment variable. What i want to do is go back one level from the "Tools" folder, the go into IDE/Extensions, something like VS100COMNTOOLS..\IDE\Extensions. This is my code:

namespace TemplatesCustomAction
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult CustomAction1(Session session)
        {

            var vspath = Environment.GetEnvironmentVariable("VS100COMNTOOLS");

            session["VSINSTALLATIONFOLDER"] = string.Format(@"{0}\..\IDE\Extensions", vspath);



            return ActionResult.Success;
        }
    }
}
like image 227
user1741243 Avatar asked Dec 12 '12 16:12

user1741243


1 Answers

Use Path.GetFullPath:

var pathWithParent = string.Format(@"{0}\..\IDE\Extensions", vspath);
session["VSINSTALLATIONFOLDER"] = Path.GetFullPath(pathWithParent);

Though I'd also rather use Path.Combine:

var pathWithParent = Path.Combine(vspath, @"\..\IDE\Extensions");
like image 184
Oded Avatar answered Sep 28 '22 20:09

Oded