【发布时间】:2017-03-18 21:05:22
【问题描述】:
我有一个在数百台服务器上运行的商业 ASP.NET 应用程序。当应用尝试移动通过 UNC 语法访问的文件共享上的目录时,一位客户遇到以下错误。
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 帐户。我已确认它对文件共享目录具有“修改”权限。
什么样的服务器配置或权限条件会触发此错误?我自己进行了许多测试,但无法重现。
【问题讨论】:
-
移动目录意味着删除原始目录及其文件。如果没有足够的权限,或者如果原始目录中的文件是“打开的”,那将会失败。或者也许只是其中的第二部分。
-
它也可能是使用该文件的用户计算机上的防病毒软件...是否总是失败。如果您尝试使用资源管理器手动移动文件,您会得到什么?
标签: c# asp.net .net system.io.directory