【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;
}

http://bbs.csdn.net/topics/390349037

posted @ 2016-11-28 08:54  霍莉雪特  阅读(2151)  评论(0编辑  收藏  举报