Voi*_*ing 1 c# asp.net using-directives webmatrix
我试图在WebMatrix Server.MapPath()的单独.cs文件中使用.
我可以使用这个方法 HttpContext.Current.Server.MapPath("~/SomeDirectory/someFile.txt")
但我HttpContext.Current每次都要打字吗?
是不是有任何使用指令来缩短我的输入,Server.MapPath就像在.cshtml文件中编码一样?
我看过这里,但没有一个答案对我有用.可能是因为其中的答案并不针对asp.net-webpages,WebMatrix环境.
http://www.sitepoint.com/forums/showthread.php?167802-Server-MapPath-in-C-class
另外,如果有一种备忘单可以帮助我找到C#.net使用指令,考虑到我的环境,让我知道我在哪里可以找到它绝对是一个可以接受的答案.
您可以将Server属性分配给变量以节省一些输入:
var server = HttpContext.Current.Server;
var file = server.MapPath("~/SomeDirectory/Somefile");
Run Code Online (Sandbox Code Playgroud)
要回答帖子标题中提出的问题 - 类文件中需要的using指令是System.Web:
using System.Web;
Run Code Online (Sandbox Code Playgroud)
我不知道任何"备忘单".经验和对MSDN帮助的熟悉程度越来越高,Resharper也是如此,如果你能负担得起并拥有完整版的Visual Studio.
| 归档时间: |
|
| 查看次数: |
4076 次 |
| 最近记录: |