How to navigate a few folders up?

前端 未结 11 2294
感动是毒
感动是毒 2020-11-29 20:52

One option would be to do System.IO.Directory.GetParent() a few times. Is there a more graceful way of travelling a few folders up from where the executing assembly resides?

11条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-29 21:10

    This is what worked best for me:

    string parentOfStartupPath = Path.GetFullPath(Path.Combine(Application.StartupPath, @"../"));

    Getting the 'right' path wasn't the problem, adding '../' obviously does that, but after that, the given string isn't usable, because it will just add the '../' at the end. Surrounding it with Path.GetFullPath() will give you the absolute path, making it usable.

提交回复
热议问题