Directory.CreateDirectory followed by Directory.Move  
Author Message
velin





PostPosted: Top

ASP.Net >> Directory.CreateDirectory followed by Directory.Move

Hi all,
I'm having a really frustrating problem. I have a web application that
needs to modify the directory structure of the underlying files. The
problem I'm having is that after the system creates a sub-directory in an
existing directory, and then I try to move the parent directory, I get an
access denied error. I've tried setting the resultant directory object to
nothing after creating it, among other things. I also tried running the
subs that do the directory io both from instanced object, as well as from
shared objects. Nothing seems to free the directory up except for time....
more time than I'm willing to accept. Is there anyway around this? Maybe
force garbage collection?

Here is the code snippet....

' Create the sub-directory
Dim d As DirectoryInfo =
IO.Directory.CreateDirectory(Current.Server.MapPath(Path))
d = Nothing

' And on a totally separate instance of the page, after creating the
sub-directory, move (rename) the parent directory
Dim d As New DirectoryInfo(Current.Server.MapPath(Path))
d.MoveTo(Current.Server.MapPath(newPath))
d = Nothing

There are no file conflicts that I can see, ie the destination directory
doesn't already exist, I'm not overwriting anything, etc. Once the
sub-directory is created, it inherits permissions from the parent, so that's
not the problem. This really shouldn't be a big deal, but it's got me
stumped. Any suggestions?

Thanks,
Matt

Web Programming445