Relative path to txt in ASP

Asked

Viewed 219 times

2

Good afternoon, I am generating a file with Asp net the function saved in the hard drive if I put the path, however this file will be saved in a server and I’m having difficulty to put the relative path of where this file will be saved, I don’t know if I’m using the right function because I’m new.

function I’m using:

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

error generated:

Details of Exception§System.IO.Directorynotfoundexception: Unable to locate a part of the path 'C: Program Files (x86) IIS Express ~ Writelines.csv'.

  • 1

    This might help you: https://stackoverflow.com/questions/1268738/asp-net-mvc-find-absolute-path-to-the-app-data-folder-from-controller

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.

0

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

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.