![](/img/trans.png)
[英]System.IO.FileNotFoundException: 'The system cannot find the file specified (with SetWallpaperAsync)
[英]System.IO.FileNotFoundException : Cannot able to find the uploaded file
我们有2台Web服务器提供负载平衡服务。 每个IIS主机都有一个临时文件夹D:\\ Website \\ PTSMAM \\ UploadFolder \\,用于放置上载的文件。 当用户提交上传文件时,它将上传文件到UploadFolder,然后将上传的文件移动到永久存储中。 如果用户的请求直接发送到Server1,则会发生以下异常
System.IO.FileNotFoundException:找不到文件'D:\\ Website \\ PTSMAM \\ UploadFolder \\ G201323200010081.txt'。 文件名:System.IO .__ Error.WinIOError中的'D:\\ Website \\ PTSMAM \\ UploadFolder \\ G201323200010081.txt'(Int32 errorCode,String mayFullPath)
在System.IO.File.Move(字符串sourceFileName,字符串destFileName)
在E:\\ PTSMAM_Source \\ PTS_MAM \\ PTS_MAM3.Web \\ DataSource \\ WSARCHIVE.asmx.cs:line 1655中的PTS_MAM3.Web.DataSource.WSARCHIVE.fileMove(ClassUploadFileClass x,String scase)
但是文件“ D:\\ Website \\ PTSMAM \\ UploadFolder \\ G201323200010081.txt”存在于其文件夹中。
如果我在Server2中执行上载作业,则工作正常。 这是为什么? Server1:D:\\ Website \\ PTSMAM \\ UploadFolder和Server2:D:\\ Website \\ PTSMAM \\ UploadFolder是否可能不同?
以下是源代码。 我认为异常是由System.IO.File.Move(fileFrom,fileDest);引起的;
private bool fileMove(ClassUploadFileClass x, string scase)
{
string fileFrom = string.Empty;
string fileFromV = string.Empty;
string fileDest = x.strDirectory;
//string fileDest2 = string.Concat(System.IO.Path.GetDirectoryName(fileDest), @"\", System.IO.Path.GetFileNameWithoutExtension(fileDest), "_M", System.IO.Path.GetExtension(fileDest));
string fileDest2 = string.Concat(System.IO.Path.GetDirectoryName(fileDest), @"\", System.IO.Path.GetFileNameWithoutExtension(fileDest), "_M.jpg");
string TempDir = Server.MapPath("/") + @"UploadFolder\";
//MAM_PTS_DLL.SysConfig obj = new MAM_PTS_DLL.SysConfig();
//string dirPhoto = obj.sysConfig_Read("/ServerConfig/STO_Config/UPLOAD_FOLDER_PHOTO");
//string dirDoc = obj.sysConfig_Read("/ServerConfig/STO_Config/UPLOAD_FOLDER_DOC");
//string dirAudio = obj.sysConfig_Read("/ServerConfig/STO_Config/UPLOAD_FOLDER_AUDIO");
try
{
//MAM_PTS_DLL.Log.AppendTrackingLog("WSARchive/fileMove", MAM_PTS_DLL.Log.TRACKING_LEVEL.INFO, "Path = " + fileDest);// + @"\" + x.strFileId + "." + x.strOExtensionName);
switch (scase)
{
case ("Photo"):
fileFrom = string.Concat(TempDir, x.strFileId, ".", x.strOExtensionName);//@"\\10.13.220.2\uploadfolder\Pictures\"
//fileFromV = string.Concat(TempDir, x.strFileId, "_M.", x.strOExtensionName);//@"\\10.13.220.2\uploadfolder\Pictures\"
fileFromV = string.Concat(TempDir, x.strFileId, "_M.jpg");
break;
case ("Audio"):
fileFrom = string.Concat(TempDir, x.strFileId, ".", x.strOExtensionName);//@"\\10.13.220.2\uploadfolder\Audios\"
break;
case ("Doc"):
fileFrom = string.Concat(TempDir, x.strFileId, ".", x.strOExtensionName);
break;
case ("LowVideo"):
fileFrom = string.Concat(TempDir, x.strFileId, ".", x.strOExtensionName);
break;
}
string dirPath = System.IO.Path.GetDirectoryName(fileDest);
if (!System.IO.Directory.Exists(dirPath))
System.IO.Directory.CreateDirectory(dirPath);
System.IO.File.Move(fileFrom, fileDest); // + @"\" + x.strFileId + "." + x.strOExtensionName);
if (scase == "Photo")
System.IO.File.Move(fileFromV, fileDest2);
return true;
}
catch (Exception ex)
{
MAM_PTS_DLL.Log.AppendTrackingLog("File Move Problem", MAM_PTS_DLL.Log.TRACKING_LEVEL.ERROR, x.strOFileName + ",ex = " + ex.ToString());
return false;
}
}
查看文件夹的权限。 IIS应用程序池用户是否可以访问(读取/写入)? 如果可以,请尝试以应用程序池用户身份登录并查看该文件夹。
假设文件存在并且您检查它确实存在。
D:\\Website\\PTSMAM\\UploadFolder
IIS_IUSRS
(应选中复选框完全控制),然后单击“确定”。 现在应该解决此问题。
注意 :不建议完全控制,因此,如果出于安全考虑,必须决定需要什么权限。
其他问题可能是因为您使用的是其他驱动器( D:\\Website\\PTSMAM\\UploadFolder
),代码string TempDir = Server.MapPath("/") + @"UploadFolder\\";
将找不到正确的路径
Server.MapPath
将开始从用于托管Web应用程序的文件夹中查找。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.