【C#/WPF】获取项目的根目录(Root Directory)
/// <summary>
/// 获得项目的根路径
/// </summary>
/// <returns></returns>
public string GetProjectRootPath()
{
string rootPath = "";
string BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory; // F:\WAF Projects\mjl\code\HomeDecorationPSD\HomeDecorationPSD\bin\Debug\
// 向上回退三级,才能到项目的根目录
rootPath = BaseDirectoryPath.Substring(0, BaseDirectoryPath.LastIndexOf("\\")); // 第一个\是转义符,所以要写两个
rootPath = rootPath.Substring(0, rootPath.LastIndexOf("\\"));
rootPath = rootPath.Substring(0, rootPath.LastIndexOf("\\")); // F:\WAF Projects\mjl\code\HomeDecorationPSD\HomeDecorationPSD\
return rootPath;
}