Relative path to txt in ASP

2

Good afternoon, I am generating a file with Asp net the function saved in HD if I put the path, however this file will be saved on a server and I am having difficulty to place the relative path of the location where this file will be saved, I do not know if I'm using the correct function because I'm new.

function I'm using:

 string[] lines = {ENAME, FNAME,LNAME };
        System.IO.File.WriteAllLines(@"~/WriteLines.csv", lines);

error generated:

  

Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C: \ Program Files (x86) \ IIS Express \ ~ \ WriteLines.csv'.

    
asked by anonymous 23.10.2018 / 20:09

2 answers

3

To get the relative path, you can use this form:

 string[] lines = {ENAME, FNAME,LNAME };
        System.IO.File.WriteAllLines(Server.MapPath("~/WriteLines.csv"), lines);

So, just concatenate with your code.

The Server.MapPath code maps to the corresponding physical directory.

    
23.10.2018 / 20:13
0

Use the Server.MapPath("~/WriteLines.csv") function. It would look like this:

string[] lines = {ENAME, FNAME,LNAME };
System.IO.File.WriteAllLines(Server.MapPath("~/WriteLines.csv"), lines);
    
23.10.2018 / 20:24