Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory.Move() is throwing a weird IOException

Status
Not open for further replies.

afroblanca

Programmer
Jul 15, 2005
67
US
Hello all. I'm trying to move a folder and all of its contents to a different location using Directory.Move(). However, when I try to do this, I get the following IOException :

Access to the path 'c:\lepidopterasites\MySite\content\userGenerated\articles\Cogswell-Cogs\This-is-the-original-folder\images\title\' is denied.

Here is my code :

Directory.CreateDirectory(newImagesFolder);
Directory.Move(oldTitleImageFileSystemPath, newImagesFolder);

Here are the values for the variables :

newImagesFolder : c:\lepidopterasites\MySite\content\userGenerated\articles\Cogswell-Cogs\a-new-folder-move-stuff-here\images\
oldTitleImageFileSystemPath : c:\lepidopterasites\MySite\content\userGenerated\articles\Cogswell-Cogs\This-is-the-original-folder\images\title\

The folder referenced in oldTitleImageFileSystemPath definitely exists. Furthermore, I have temporarily assigned the user "Everyone" Full Control access to the c:\lepidopterasites folder, so I know that it isn't a permissions issue. What's weird is that the exception is an IOException. In the documentation, we are given the following possible reasons for this method throwing an IOException :

1) An attempt was made to move a directory to a different volume.
2) destDirName already exists.
3) The sourceDirName and destDirName parameters refer to the same file or directory.

And I know for a fact that none of these conditions are true.

So I'm kinda stuck. Do you know why I'm getting this exception? If not, can you give me any ideas on how to troubleshoot this?

Thanks for the help.
 
Are you doing any impersonation in your application? If so, you will need to grant access to that individual user. If not, you will need to grant access to the ASPNET or NETWORK SERVICE user (depending on which OS you have).


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Well, I gave "Everyone" full control, and I also gave ASPNET full control, and I still have the same problem.

Interestingly enough, if I take out the Directory.CreateDirectory, I get this IOException : Could not find a part of the path

(of course it doesn't tell you which path, the source or the dest)

I know for a fact that the source dir exists. If I examine the value of the variable, and paste it into windows explorer, it navigates to the folder just fine.

Who knew that moving files could be so difficult?
 
if either of the machines is a remote machine (not the web server) then you also need to configure delegation between the web server and the remote server(s).

delegation will continue to pass along the user credentials to the remote machine.

this is done through active directory, computers, delegation.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
I'm using Windows XP, not using any impersonation (that I know of)

I did made a bit of progress on this problem.

If I make the source directory manually, through windows explorer, my code has no problem executing the Directory.Move() method. However, if I create the source directory through code, using Directory.Create(), my code cannot move the folder! It has no problem creating the directory, it just has trouble moving it once it has been created.

The reason that I doubt it's a permissions issue is that I've given the ASPNET role full control over the site root and all subdirectories.

Any idea what could be causing this?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top