简体   繁体   中英

File.Move Error - System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv

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);

检查该文件夹上的用户权限。

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().

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM