我有一个商业ASP.NET应用程序运行在数百台服务器上。当应用程序尝试移动通过UNC语法访问的文件共享上的目录时,一位客户正在经历以下错误。Directory.Move目录结果不为空错误
System.IO.IOException: The directory is not empty.
堆栈跟踪:
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)
的代码看起来像这样(简化):
var sourceDir = @"\\server\storage\folder1";
var destDir = @"\\server\storage\folder2";
System.IO.Directory.Move(sourceDir, destDir);
我要指出的是,当该目录为空的代码是否能够成功。它应该在包含文件时工作,而且确实适用于其他客户。
ASP.NET应用程序在IIS中使用AD帐户运行应用程序池标识。我已确认它具有对文件共享目录的“修改”权限。
什么样的服务器配置或权限条件可能会触发此错误?我已经自行运行了一些测试,无法复制它。
移动目录意味着删除原始目录及其文件。如果没有足够的权限,或者原始目录中的文件“打开”,则会失败。或者也许只是第二部分。 –
它可能也是该用户计算机上使用该文件的防病毒软件... 它是否总是失败。如果您尝试使用资源管理器手动移动文件,您会得到什么? – Phil1970