I have the following sample code.
private DirectoryInfo PathDirectoryInfo
{
get
{
if (_directoryInfo == null)
{
// Some logic to create the path
// var path = ...
_directoryInfo = new DirectoryInfo(path);
}
return _directoryInfo;
}
}
public voide SaveFile(string filename)
{
if (!PathDirectoryInfo.Exists)
{
PathDirectoryInfo.Create();
}
// PathDirectoryInfo.Exists returns false despite the folder has been created.
bool folderCreated = PathDirectoryInfo.Exists; // folderCreated == false
// Save the file
// ...
}
According to MSDN:
Exists property: true if the file or directory exists; otherwise, false.
Why Exists returns false after directory has been created? Am I missing something?