不是好方法!
因为工程里面没有根目录配置(web.config)所以只能获取当前目录
/// <summary>
/// 获取路径
/// </summary>
/// <param name="filespec">路径</param>
/// <returns></returns>
public string GetRelativePath(string filespec)
{
string rootPath = "";
// 获取当前路径
string BaseDirectoryPath = AppDomain.CurrentDomain.BaseDirectory;
// 由于路径原因,向前倒三级
rootPath = BaseDirectoryPath.Substring(0, BaseDirectoryPath.LastIndexOf("\\"));
rootPath = rootPath.Substring(0, rootPath.LastIndexOf(@"\"));
rootPath = rootPath.Substring(0, rootPath.LastIndexOf("\\")) + filespec;
return rootPath;
}
只能说是懒人方法了