在Window Application中使用HttpContext.Current.Server.MapPath?

Wor*_*gon 4 .net c#

我可以在窗口应用程序中执行类似的操作吗?

HttpContext.Current.Server.MapPath("Email/ForgotPassword.txt"));
Run Code Online (Sandbox Code Playgroud)

该项目是基于Web的应用程序.

我的下一个项目基本上是一个窗口服务......

寻求建议.

Nir*_*ngh 7

要获取运行Exe的路径(这是添加"电子邮件"等路径的好位置),请使用:

string filePath = Application.StartupPath + "\\Email\\ForgotPassword.txt";
Run Code Online (Sandbox Code Playgroud)

在VS和..\Email路径上运行它时,此路径是..\bin\debug\Email路径,在安装后运行它.

很少有替代方法可以像这些一样访问目录路径:

string appPath = Path.GetDirectoryName(Application.ExecutablePath);
Run Code Online (Sandbox Code Playgroud)

要么

using System.IO;
using System.Reflection;

string path = Path.GetDirectoryName(
                     Assembly.GetAssembly(typeof(MyClass)).CodeBase);
Run Code Online (Sandbox Code Playgroud)

你可以使用Path类进行操作,比如获取完整路径,目录名等等.

查看此MSDN论坛主题如何获取当前目录路径c#winfows以 获取详细信息.

正如你期望像网络一样做Windows应用程序..这是不可能的.