Hello All,
I cannot create directory on linux ,it is giving error. The error is "access to the path is denied"
I am using following code in c#.net core
if (!Directory.Exists(logPath))
{
Directory.CreateDirectory(logPath);
}
Please help me on this
Hello All,
I cannot create directory on linux ,it is giving error. The error is "access to the path is denied"
I am using following code in c#.net core
if (!Directory.Exists(logPath))
{
Directory.CreateDirectory(logPath);
}
Please help me on this
What's your intention to use a relative path like Home/ProjectName/Log/? The working directory you execute the code determines the absolute path of Home/ProjectName/Log/ and that result can still be a path you don't have access to. To test out better, set logPath to an absolute path, which immediately tells you what's up.
Yes,I used other path also,it is giving same error."Access to the path is denied."
other path : Home/Documents/ProjectName/Log/
Please help me on this
I think he means "/Home/ProjectName/Log/" instead of "Home/ProjectName/Log/", provided you've created "/Home/ProjectName/Log/" and granted write access to the user running that application.
Although I think the more common location would be "/var/log/ProjectName/" or "$HOME/.ProjectName/log", I should add. (Putting "." in front of file/directory name will make it hidden by default)
Hello all,
In linux system do we need to give permission for folders? like below,
sudo chmod -R a+rwx /home
If i give this command then log file creation is happening.
Please help me on this..
/home is a different file path (root directory of all users' home directories) than what you showed earlier. You shouldn't change its permissions, and instead should follow my answer above.
Hi,
This Environment.GetFolderPath(Environment.SpecialFolder.Personal) is giving Home directory in linux.
Now the log file is created in /Home/Test/Log/log.txt
Home and home directory both are different in Linux?
if i go Home or home in linux,both are pointing to same location
Like I commented above, you specified an invalid path of Home/Test/Log.
Please study articles such as this to get started.
The actual path value of the folder you created is Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Personal), "Test", "Log").

Please find the path location snapshot in ubuntu linux.
I created folder ("Home/Test/Log/") manually..but again !Directory.Exists(logPath) returning false and it will go if block,
if (!Directory.Exists(logPath))
{
Directory.CreateDirectory(logPath);
}
I created folder ("Home/Test/Log/") manually...
The problem is that your folder name is missing the initial "/". In order to reliably create the folder, you need to specify an absolute path. This means that it has to start with a "/" and then list all the intermediate folders starting from the root of the filesystem. Otherwise it could be interpreted as being "anywhere" (actually it is taken from the current directory, which could be anything depending on how you start the program. No, the current directory is not your home directory, and it is also not the directory where you place the executable of your program).
In summary, something like this (but adapted to your filesystem): "/users/yourName/Home/Documents/ProjectName/Log". Do not forget the "/" at the beginning, and do not add a "/" at the end.
12 people are following this question.
How to give input parameters to systemctl start testapp.service using C#.Net Core and systemd?
How to find daemon application version using .Net Core 3.1 with systemd?
How to solve Access to the path is denied Error in C#.NET Core application
How to close .net core console application on linux machine?