A folder can be created on your C:\ (the default drive on which the OS is installed). folder location C:\Logs\WZCLogs\ . You can confirm that the folder was created somewhere on the disk by executing the code again, this time if (!Directory.Exists(FilePath)) will return true . Since you did not specify any locations, the compiler accepts So. Check if it is created or not;
You can extend the attempt like this:
try { Directory.CreateDirectory(FilePath); } catch (Exception ex) {
If the path is wrong, an exception will definitely be thrown; I tried with "X: \ sample", which gives me an exception:
Could not find part of path 'X: \ sample
Whereas if I tried with Logs\WZCLogs which would not throw any exceptions the first time, and also skip if for the second time; From here I discovered that the folder was created somewhere else;
You can make these changes to make them work:
string FilePath=Path.Combine(HostingEnvironment.ApplicationPhysicalPath, @"Logs\WZCLogs");
source share