Question

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));
     }
Was it helpful?

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top