I developed a simple .net application that scrapes some data from web and saves it in a file (file and the proejct exe file are in the same folder ).
It runs fine on windows, but when i run it on mac using ‘Mono’ i get this error
Access to the path ‘[path]’ is denied.
I am creating the accessing this file using Directory.GetCurrentDirectory.
here is the path i am using:
System.IO.Directory.GetCurrentDirectory() + "\\abc.csv";
You should not concatenate directories using strings, not if you want your applications to be cross platform.
BAD:
Good:
Using
Path.Combinewill ensure the correct directory separators are used.If you have to traverse through several directories, use
Path.Combinerepeatedly: