简体   繁体   中英

Get relative path for a file asp.net

I have an MVC4 application, one controller method takes some files (this files has some Json Objects), read it proccessit then deleteit.

Those files are uploaded to my site using ftp. My Project structures is sometrhing like this

wwwroot
  bin
  content
  images
  scripts 
  suscribers // This is my ftp folder 
    _suscriber1
      _proccess1
        file1.txt //This is a Json file 
        file2.txt 
        ...
      _proccess2
      ...
    _suscriber2 
    ...

All my files (file1.txt...) are loaded ok. At my controller, i'm trying to read file1.txt this way:

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();

My problema is that it is throwing me a filenotfound exception.

What is the right way to read file1.txt and get its content?

尝试使用Server.MapPath("_File1.txt");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM