在獲得結構中超過4000000個jpeg文件後,我們遇到添加新問題的問題。 File.Copy拋出異常:由於文件系統限制,請求的操作無法完成。File.Copy錯誤:由於文件系統限制,請求的操作無法完成
任何解決方案?
信息
- 系統:的Windows Server 2008 SP1 64位
- 安裝路徑:http://support.microsoft.com/kb/967351/en-us?fr=1
- 碎片整理:做
代碼
public bool AddFile(Uri uri, string path, bool withDelete = false)
{
var sourceFilePath = path;
var destinationFilePath = Path.GetFullPath(uri.LocalPath);
try
{
if (!File.Exists(sourceFilePath))
{
sourceFilePath = Directory.EnumerateFiles(sourceFilePath).FirstOrDefault();
destinationFilePath = Path.Combine(destinationFilePath, Path.GetFileName(sourceFilePath));
}
if (!Directory.Exists(Path.GetDirectoryName(destinationFilePath)))
Directory.CreateDirectory(Path.GetDirectoryName(destinationFilePath));
if (withDelete && File.Exists(destinationFilePath))
File.Delete(destinationFilePath);
File.Copy(sourceFilePath, destinationFilePath);
return true;
}
catch (Exception exc)
{
ServiceCore.GetLogger().Error(exc);
throw exc;
}
}
堆棧跟蹤
2013-03-28 14:10:48.3784[Info]: 47356388:Unive.NetService.SimpleServices.DocumentManagementSerivce..ctor: Entry
2013-03-28 14:10:48.4740[Info]: Static:Unive.NetService.SimpleServices.DocumentManagementSerivce..ctor: Success
2013-03-28 14:10:48.4899[Info]: 47356388:Unive.NetService.SimpleServices.DocumentManagementSerivce.UploadFile: Entry
2013-03-28 14:11:26.3277[Error]: Exception
Message:The requested operation could not be completed due to a file system limitation
Source:mscorlib
Stack Trace: at System.IO.__Error.WinIOError(Int32 errorCode, String maybeFullPath)
at System.IO.File.InternalCopy(String sourceFileName, String destFileName, Boolean overwrite)
at Unive.NetService.Business.SimpleFileClient.AddFile(Uri uri, String path, Boolean withDelete) in D:\Tag Prografix\Unive.NetService\Business\SimpleFileClient.cs:line 33
TargetSite:Void WinIOError(Int32, System.String)
2013-03-28 14:11:26.5029[Error]: 47356388:Unive.NetService.SimpleServices.DocumentManagementSerivce.UploadFileException
Message:The requested operation could not be completed due to a file system limitation
Source:mscorlib
Stack Trace: at Unive.NetService.Business.SimpleFileClient.AddFile(Uri uri, String path, Boolean withDelete) in D:\Tag Prografix\Unive.NetService\Business\SimpleFileClient.cs:line 42
at Unive.NetService.Business.FileService.UploadFile(Int64 fileId, String fileName, String path, Boolean isDiagram) in D:\Tag Prografix\Unive.NetService\Business\FileService.cs:line 80
at Unive.NetService.SimpleServices.DocumentManagementSerivce.UploadFile(Int64 fileId, String fileName, String path) in D:\Tag Prografix\Unive.NetService\SimpleServices\DocumentManagementSerivce.asmx.cs:line 100
TargetSite:Void WinIOError(Int32, System.String)
這是一種可能性:http://blogs.technet.com/b/seanearp/archive/2011/07/06/file-system-limitation.aspx –
http://stackoverflow.com/questions/197162/ ntfs-performance-and-large-volumes-of-files-and-directories/291292#291292(_「然後或者」_是給你的) –