c# Environment.SpecialFolder.MyDocuments creating issue

T.Zacks 3,996 Reputation points
2021-07-07T12:29:28.55+00:00

I want to create a log folder in this location C:\Users\administrator\Documents i tried this code but below code not able to create directory in that location. program not throwing error but not able to create folder in Documents folder. i tried this code

LogPath = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\Log";

if (!Directory.Exists(LogPath))
{
    Directory.CreateDirectory(LogPath);
}

where i made the mistake for which log folder not creating in document folder?
please share the right code. thanks

Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. Michael Taylor 60,161 Reputation points
    2021-07-07T13:26:02.407+00:00

    Your code looks correct. Are you sure you are looking at the correct directory? This code will create the folder under the Documents of the user running the code. Verify the full path set by LogPath is correct and then step through the code to confirm that Exists is returning true if it doesn't exist.


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.