如何在服务器上发布应用程序时使用C#读取txt文件 [英] How to read txt file using C# when you published your application on server
问题描述
你好,
当我在服务器上发布我的web应用程序后,代码没有读取文本文件值。但是当我在本地主机上运行web应用程序时,它的读取文本文件值。当我在服务器上托管我的网络应用程序时有什么问题,请给我解决方案如何从服务器上读取它?
我尝试过:
Hello,
When i am published my web application on sever following code not read text file value. But when i am run web application on local host its read text file value. what is the problem when i am host my web app on server, please give me solution how read it from server??
What I have tried:
string text;
var fileStream = new FileStream(@"c:\file.txt", FileMode.Open, FileAccess.Read);
using (var streamReader = new StreamReader(fileStream, Encoding.UTF8))
{
text = streamReader.ReadToEnd();
}
推荐答案
当然不会 - 你会得到一种无效路径或安全例外。您无法访问虚拟根文件夹之外的C:\。
读取此内容: [ ^ ]
Of course it won't - you would get a form of invalid path or security exception. You can't access "C:\" outside of your virtual root folder.
Have a read of this: [^]
您刚刚问了同样的问题,只是另一种方式。
如何使用javasacript在文本框中阅读和显示文本文件值 [ ^ ]
答案是一样的。
You have just asked the same question, just another way.
How to read and display text file value in text box using javasacript[^]
The answer is the same.
readTextFile("file:///C:/MACID.txt");
JavaScript和WebApps没有直接访问权限o出于安全原因,用户文件系统。
读取本地文件的唯一方法是通过打开文件对话框和用户批准。
JavaScript and WebApps do not have direct access to user file system for security reasons.
The only way to read a local file is through 'open file' dialog and with user approval.
这篇关于如何在服务器上发布应用程序时使用C#读取txt文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!