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

.NET CLI
.NET CLI
A cross-platform toolchain for developing, building, running, and publishing .NET applications.
323 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,275 questions
.NET Runtime
.NET Runtime
.NET: Microsoft Technologies based on the .NET software framework.Runtime: An environment required to run apps that aren't compiled to machine language.
1,125 questions
{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) 4,742 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..