在窗口应用程序中使用 HttpContext.Current.Server.MapPath?

2023-12-01

我可以在窗口应用程序中做这样的事情吗?

HttpContext.Current.Server.MapPath("Email/ForgotPassword.txt"));

该项目是一个基于网络的应用程序。

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

寻求建议。


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

string filePath = Application.StartupPath + "\\Email\\ForgotPassword.txt";

该路径在VS上运行时为..\bin\debug\Email路径,在安装后运行时为..\Email路径。

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

string appPath = Path.GetDirectoryName(Application.ExecutablePath);

or

using System.IO;
using System.Reflection;

string path = Path.GetDirectoryName(
                     Assembly.GetAssembly(typeof(MyClass)).CodeBase);

你可以用Path类似获取完整路径、目录名等的类。

检查此 MSDN 论坛主题c# windows中如何获取应用程序的当前目录路径了解详情。

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

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在窗口应用程序中使用 HttpContext.Current.Server.MapPath? 的相关文章

随机推荐