Directory.CreateDirectory followed by Directory.Move

Discussion in 'ASP .Net' started by Matt MacDonald, Jan 30, 2008.

  1. 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
     
    Matt MacDonald, Jan 30, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. GM
    Replies:
    2
    Views:
    2,252
  2. Eran Kampf
    Replies:
    7
    Views:
    6,253
    Eran Kampf
    Oct 13, 2004
  3. Andrew R. Jones
    Replies:
    2
    Views:
    3,576
    Andrew R. Jones
    Jan 5, 2006
  4. Chad
    Replies:
    6
    Views:
    2,811
  5. Wayne Brantley

    Directory.CreateDirectory always fails.

    Wayne Brantley, Jul 11, 2005, in forum: ASP .Net Security
    Replies:
    8
    Views:
    326
    [MSFT]
    Aug 3, 2005
Loading...

Share This Page