Reputation: 53
So my filesystem looks like this on absolute path:
C:\Users\myname\source\repos\projectname\projectname\bin\Debug\data\orders
and I want to use relative path like this:
string path = "~/data/orders/" + sdat + ".txt";
using (StreamWriter writer = new StreamWriter(path))
{
writer.WriteLine(lines[0]);
writer.WriteLine(lines[1]);
writer.WriteLine(lines[2]);
}
but it gives the error:
System.IO.DirectoryNotFoundException: 'Nem található a következő elérési út egy része.: „C:\Users\myname\source\repos\projectname\projectname\bin\Debug\~\data\orders\2021.06.26.txt”.'
Nem található a következő elérési út egy része means Path not found
Upvotes: 1
Views: 50
Reputation: 2378
Change
string path = "~/data/orders/" + sdat + ".txt";
to
string path = "data\\orders\\" + sdat + ".txt";
"~" is for url in asp.net not for local filesystem.
Upvotes: 1