Directory.CreateDirectory error on linux using C#.net core - Error: access path is denied

Prabs 1 Reputation point
2021-04-07T10:00:12.823+00:00

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

Developer technologies .NET .NET Runtime
Developer technologies .NET .NET CLI
Developer technologies C#
{count} votes

3 answers

Sort by: Most helpful
  1. Prabs 1 Reputation point
    2021-04-09T08:42:38.023+00:00

    86213-linu.jpg

    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);
    }


  2. Lex Li (Microsoft) 6,037 Reputation points Microsoft Employee
    2021-04-10T03:33:45.977+00:00

    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").

    0 comments No comments

  3. Prabs 1 Reputation point
    2021-04-14T07:14:58.98+00:00

    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..


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.