使用Server.Mappath走两头夹回从根 [英] Server.MapPath to go two folder back from root

查看:112
本文介绍了使用Server.Mappath走两头夹回从根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我如何做到这一点:

Here is how I do it:

HttpContext.Current.Server.MapPath(@"~\~\~\Content\")

HI知道'。对于项目的根,但如何去几个文件夹回来?

HI know that '.' is for the root of the project, but how to go a few folders back?

推荐答案

如果你真的需要祖父母路径,可以使用根路径<一个得到它href=\"http://msdn.microsoft.com/en-us/library/system.io.path.getdirectoryname.aspx\"><$c$c>Path.GetDirectoryName():

If you really need the grandparent path, you can get it from the root path using Path.GetDirectoryName():

string root = Server.MapPath("~");
string parent = Path.GetDirectoryName(root);
string grandParent = Path.GetDirectoryName(parent);

但是,你的Web应用程序很可能将没有权限来读取或写入存在 - 我不知道你会用它做什么。

But your web app very likely won't have permission to read or write there - I'm not sure what you're going to do with it.

这篇关于使用Server.Mappath走两头夹回从根的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆