F
Frederico Caldeira Knabben
Hello,
I'm having a problem when trying to use the Directory.CreateDirectory()
method. It throws a DirectoryNotFoundException exception. I'll try to
illustrate it:
Suppose you have the following (existing) directory:
d:\Sites\MySite\
And you whant to create the following:
d:\Sites\MySite\MyDir1\MyDir2\
It should be an easy task. Just call CreateDirectory(), like this:
Directory.CreateDirectory( "d:\Sites\MySite\MyDir1\MyDir2\" ) ;
And it will create all missing dirs... in this case "MyDir1" and "MyDir2".
But... if you don't have read permissions of the "d:\" or "d:\Sites\"
directory, a DirectoryNotFoundException exception is thrown.
I took a look around and many people are facing the same problem. My opinion
is that it is a "big bug" in the DotNet Framework implementation.
The problem is the way the method works... it check if exists and create the
directories starting from the root in this order:
d:\ (Check exists)
d:\Sites\ (Check exists)
d:\Sites\MySite\ (Check exists)
d:\Sites\MySite\MyDir1\ (Check exists and create)
d:\Sites\MySite\MyDir1\MyDir2\ (Check exists and create)
It should do the inverse... starting from the back until the directory is
found (adding the missing ones in and array and after that create then).
It is easy to solve the problem in a controlled environment. You just need
to give Read permissions to the entire path starting from the root (even if
you don't want to do that). But in other cases (like a site hosted in a
server were you have no control), this is impossible to do.
Is there a workaround to create a directory in these situations?
Thanks in advance,
Frederico Caldeira Knabben
I'm having a problem when trying to use the Directory.CreateDirectory()
method. It throws a DirectoryNotFoundException exception. I'll try to
illustrate it:
Suppose you have the following (existing) directory:
d:\Sites\MySite\
And you whant to create the following:
d:\Sites\MySite\MyDir1\MyDir2\
It should be an easy task. Just call CreateDirectory(), like this:
Directory.CreateDirectory( "d:\Sites\MySite\MyDir1\MyDir2\" ) ;
And it will create all missing dirs... in this case "MyDir1" and "MyDir2".
But... if you don't have read permissions of the "d:\" or "d:\Sites\"
directory, a DirectoryNotFoundException exception is thrown.
I took a look around and many people are facing the same problem. My opinion
is that it is a "big bug" in the DotNet Framework implementation.
The problem is the way the method works... it check if exists and create the
directories starting from the root in this order:
d:\ (Check exists)
d:\Sites\ (Check exists)
d:\Sites\MySite\ (Check exists)
d:\Sites\MySite\MyDir1\ (Check exists and create)
d:\Sites\MySite\MyDir1\MyDir2\ (Check exists and create)
It should do the inverse... starting from the back until the directory is
found (adding the missing ones in and array and after that create then).
It is easy to solve the problem in a controlled environment. You just need
to give Read permissions to the entire path starting from the root (even if
you don't want to do that). But in other cases (like a site hosted in a
server were you have no control), this is impossible to do.
Is there a workaround to create a directory in these situations?
Thanks in advance,
Frederico Caldeira Knabben