在Window应用程序中使用HttpContext.Current.Server.MapPath? [英] Using HttpContext.Current.Server.MapPath in Window Application?
问题描述
我可以在窗口应用程序中执行以下操作吗?
Can i do something like this in window Application?
HttpContext.Current.Server.MapPath("Email/ForgotPassword.txt"));
该项目是一个基于Web的应用程序。
This project is a web based application.
我的下一个项目基本上是一个窗口服务...
And my next project is basically a window service...
寻求建议。
推荐答案
要获取Exe运行所在的路径(这是添加路径(如电子邮件)的好位置),请使用:
To get the path that the Exe is running at (which is a good location to add paths like "Email"), use:
string filePath = Application.StartupPath + "\\Email\\ForgotPassword.txt";
此路径是在运行时的..\bin\debug\Email路径VS和..\在安装后运行时的电子邮件路径。
This path is the ..\bin\debug\Email path when you run it on VS and ..\Email path when you run it after installation.
很少有其他类似的方法可以访问目录路径:
There are few alternates to do this like these to access the directory path:
string appPath = Path.GetDirectoryName(Application.ExecutablePath);
或
using System.IO;
using System.Reflection;
string path = Path.GetDirectoryName(
Assembly.GetAssembly(typeof(MyClass)).CodeBase);
您可以使用路径类,例如获取完整路径,目录名称等。
you can do manipulation with the Path class like get the full path, directory name etc etc..
检查此MSDN论坛线程如何获取应用程序的当前目录路径c#winfows 以获得详细信息。
Check this MSDN forum thread How to get the current directory path c# winfows for application for details.
您希望像执行Windows应用程序一样web ..这不可能
。
As you expecting to do windows application as like web.. It is not possible.
这篇关于在Window应用程序中使用HttpContext.Current.Server.MapPath?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!