簡體   English   中英

File.Move錯誤-System.IO.FileNotFoundException:找不到文件'c:\\ windows \\ system32 \\ inetsrv

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

我不知道為什么我會在下面看到這個錯誤。 我調試時的filevPath是完全有效的(是的,映像的物理位置肯定在傳遞的filePath變量中的硬盤上),並且顯然與錯誤報告的路徑不同,看起來像是通用錯誤:

System.IO.FileNotFoundException:找不到文件'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);
    }
}

更換:

string newfileName = uploadedFileName.Replace(uploadedFileName.Substring(0, uploadedFileName.IndexOf("-")), currenSessionID);

與:

string newfileName = filePath.Replace(filePath.Substring(0, filePath.IndexOf("-")), currenSessionID);

檢查該文件夾上的用戶權限。

不確定通過查看代碼將其放置在何處,但需要使用

Server.GetPath()

查找您的Web應用程序的當前目錄。

在ASP.NET中運行時,“ c:\\ windows \\ system32 \\ inetsrv \\”是默認的“當前目錄”

如果可以提供有關引發異常時當前與每個文件位置相關的字符串的內容的更多詳細信息,我可以告訴您哪個需要調用Server.GetPath()。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM