Search code examples
c#console-applicationcreate-directory

Cannot Create Directory error


I am trying to create a directory if it does not exist. It correctly goes into the code to create the directory because it doesn't exist. But then it gives me the following error:

DirectoryNotFoundException was unhandled

Could not find part of the path "\192.168.22.2\2009"

var fileYear = createdDate.Value.Year.ToString();
var fileMonth = createdDate.Value.Month.ToString();
var rootDir = @"\\192.168.22.2";

if (!File.Exists(Path.Combine(rootDir,fileYear)))
     {
          // Create the Year folder
          Directory.CreateDirectory(Path.Combine(rootDir,fileYear));
     }

Solution

  • You need to have a share name after the @"\\192.168.22.2".
    Something like @"\\192.168.22.2\MySharedFolder".

    You cannot create a subfolder from that root dir