我正在尝试获取应用程序的根文件夹。我使用了以下代码,但这给出了bin
文件夹,但我需要的是应用程序的根文件夹。有可能得到这个吗?
// This is the full directory and exe name
String fullAppName = Assembly.GetExecutingAssembly().GetName().CodeBase;
// This strips off the exe name
String fullAppPath = Path.GetDirectoryName(fullAppName);
exe 所在的位置是应用程序的根目录。
您可以使用string appPath = Path.GetDirectoryName(Application.ExecutablePath);
获取应用程序路径。
如果您想找到解决方案所在的文件夹,我建议从 exe 位置开始,然后沿着目录树向上查找,直到到达包含 .sln 文件的文件夹。但不太确定你为什么要这样做。
编辑:刚刚发现您正在创建一个 asp.net 站点。在这种情况下,您应该能够使用下面的内容(发现here):
public static string MappedApplicationPath
{
get
{
string APP_PATH = System.Web.HttpContext.Current.Request.ApplicationPath.ToLower();
if(APP_PATH == "/") //a site
APP_PATH = "/";
else if(!APP_PATH.EndsWith(@"/")) //a virtual
APP_PATH += @"/";
string it = System.Web.HttpContext.Current.Server.MapPath(APP_PATH);
if(!it.EndsWith(@"\"))
it += @"\";
return it;
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)