我有一个 MVC4 应用程序,一个 Controller 方法需要一些文件(这个文件有一些 Json 对象),读取它处理然后删除它。
这些文件使用 ftp 上传到我的站点。我的项目结构是这样的
wwwroot
bin
content
images
scripts
suscribers // This is my ftp folder
_suscriber1
_proccess1
file1.txt //This is a Json file
file2.txt
...
_proccess2
...
_suscriber2
...
我的所有文件 (file1.txt...) 都加载正常。在我的 Controller 上,我试图以这种方式读取 file1.txt:
string suscriberDir= string.Format("_{0}", suscriber.Id);
string[] laPath = {System.AppDomain.CurrentDomain.BaseDirectory, "suscribers", suscriberDir};
string lcPath = Path.Combine(laPath);
string[] laPath2 = { lcPath, "_proccess1" , "_File1.txt" };
lcPath = Path.Combine(laPath2);
StreamReader reader = new StreamReader(lcPath);
string personas = reader.ReadToEnd();
reader.Close();
我的问题是它向我抛出一个 filenotfound 异常。
读取 file1.txt 并获取其内容的正确方法是什么?
最佳答案
尝试使用 Server.MapPath("_File1.txt");
关于c# - asp.net 获取文件的相对路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15126594/