I have no idea why I'd get this error below. The filevPath when I debug is a completely valid (yes, the physical the image is definitely there physically on the hard drive in the filePath variable that is being passed) path and obviously is not开发者_高级运维 the same path as the error is reporting which looks like some generic error:
System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv\someimage1.jpg'
private void RenameUploadedFile(string uploadedFileName)
{
string filePath = Path.Combine(WebUtil.UploadPath, uploadedFileName);
if (File.Exists(filePath))
{
try
{
string newfileName = uploadedFileName.Replace(uploadedFileName.Substring(0, uploadedFileName.IndexOf("-")), currenSessionID);
File.Move(uploadedFileName, newfileName);
}
catch (Exception ex)
{
.ErrorLog("Image Copy Error: " + ex.ToString());
throw new ApplicationException("There was an error during a rename(move) operation on the Saved Item upload file: " + filePath + " error: " + ex.ToString());
}
}
else
{
.ErrorLog("File does not exist or path is invalid for at the following filepath: " + filePath);
}
}
Replace:
string newfileName = uploadedFileName.Replace(uploadedFileName.Substring(0, uploadedFileName.IndexOf("-")), currenSessionID);
with:
string newfileName = filePath.Replace(filePath.Substring(0, filePath.IndexOf("-")), currenSessionID);
Check the user permissions on that folder.
Not sure where you need to put this by looking at your code, but you need to use
Server.GetPath()
to find the current directory of your web application.
'c:\windows\system32\inetsrv\' is the default "Current Directory" when running in ASP.NET
If you can provide more details about what every file location related string currently has in it when the exception is thrown, I can tell you which one needs the call to Server.GetPath().
精彩评论