1

I have a commercial ASP.NET application running on hundreds of servers. One customer is experiencing the error below when the app tries to move a directory on a file share accessed via UNC syntax.

System.IO.IOException: The directory is not empty.

Stack trace:

at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.Directory.InternalMove(String sourceDirName, String destDirName, Boolean checkHost)
at GalleryServer.Business.AlbumSaveBehavior.PersistToFileSystemStore(IAlbum album)
at GalleryServer.Business.AlbumSaveBehavior.Save()
at GalleryServer.Business.GalleryObject.Save()
at GalleryServer.Business.Album.MoveTo(IAlbum destinationAlbum)
at GalleryServer.Web.Controller.AlbumController.TransferToAlbum(Int32 destinationAlbumId, GalleryItem[] itemsToTransfer, GalleryAssetTransferType  transferType, GalleryItem[] createdGalleryItems)
at GalleryServer.Web.Api.AlbumsController.TransferTo(Int32 destinationAlbumId, GalleryItem[] itemsToTransfer, GalleryAssetTransferType transferType)

The code looks like this (simplified):

var sourceDir = @"\\server\storage\folder1";
var destDir = @"\\server\storage\folder2";

System.IO.Directory.Move(sourceDir, destDir);

I should note that the code succeeds when the directory is empty. It should work when it contains files, and indeed it does for other customers.

The ASP.NET app is running in IIS with an AD account for the application pool identity. I've confirmed it has 'modify' permission to the file share directories.

What kind of server configuration or permission condition could trigger this error? I've run a number of tests on my own and can't repro it.

Roger
  • 2,118
  • 1
  • 20
  • 25
  • 1
    Moving a directory implies deleting the original directory and its files. Without sufficient permissions, or if a file in the original directory is "open", that will fail. Or maybe just the second part of that. – Andrew Morton Nov 04 '16 at 23:02
  • It might also be an antivirus on that user computer that use the file... Does it always fails. If you try to manually move the files with the Explorer, what do you get? – Phil1970 Nov 05 '16 at 03:42

2 Answers2

1

Directory.Move internally calls MoveFile in kernel32.dll: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365239(v=vs.85).aspx

This results in system error 0x91 (https://msdn.microsoft.com/en-us/library/windows/desktop/ms681382(v=vs.85).aspx)

It's hard to tell from here, but there is probably a file in the source folder that can not be moved by your user account.

Peter
  • 3,916
  • 1
  • 22
  • 43
0

Can you try the answer posted here on SO? The answer does overcome restrictions on internal functionality and is much safer.

Community
  • 1
  • 1
Pratik Gaikwad
  • 1,526
  • 2
  • 21
  • 44