【发布时间】:2017-08-04 08:57:33
【问题描述】:
我正在尝试从 winform 桌面应用程序将文本写入服务器上的文件
string path = "http://www.site.info/doc.txt";
使用路径:
System.Web.HttpContext.Current.Server.MapPath(path);
我也试过这种方式:
System.Web.Hosting.HostingEnvironment.MapPath(path);
将文本写入文本文档:
using (StreamWriter _testData = new StreamWriter(Server.MapPath("~/doc.txt"), true))
{
_testData.WriteLine("TEXT");
}
好像我做错了什么,
name
Server"在当前上下文中不存在"。
不知道如何使用Server.MapPath。
它在参考文献中作为System.Web 而不是System.Web.dll,不确定,但必须相同,并且在使用时作为System.Web;
我也在使用System.Net;,所以也许我可以使用WebClient。
【问题讨论】:
-
没有多少当代网站允许您直接写入网络服务器上的文件。最好提供一个 API 来执行作业服务器端。考虑研究 REST?
-
@MickyD 你好,我只想写在我的服务器上
-
您是说WinForms 应用程序和 Web 服务器都是同一台计算机??
-
@MickyD 不,它是用户计算机上的应用程序,它写入我的服务器
-
好吧,我不明白你说的“我只想在我的服务器上写”是什么意思
标签: c# winforms server system.net system.web