简体   繁体   English

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

[英]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: 我调试时的filevPath是完全有效的(是的,映像的物理位置肯定在传递的filePath变量中的硬盘上),并且显然与错误报告的路径不同,看起来像是通用错误:

System.IO.FileNotFoundException: Could not find file 'c:\\windows\\system32\\inetsrv\\someimage1.jpg' 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);
    }
}

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. 查找您的Web应用程序的当前目录。

'c:\\windows\\system32\\inetsrv\\' is the default "Current Directory" when running in ASP.NET 在ASP.NET中运行时,“ c:\\ windows \\ system32 \\ inetsrv \\”是默认的“当前目录”

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(). 如果可以提供有关引发异常时当前与每个文件位置相关的字符串的内容的更多详细信息,我可以告诉您哪个需要调用Server.GetPath()。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 ASP零:System.IO.FileNotFoundException:找不到文件'c:\\ windows \\ system32 \\ inetsrv \\ log4net.config' - ASP Zero :System.IO.FileNotFoundException: Could not find file 'c:\windows\system32\inetsrv\log4net.config' 找不到文件 'c:\\windows\\system32\\inetsrv\\xxx.xlsx' - Could not find file 'c:\windows\system32\inetsrv\xxx.xlsx' System.IO.FileNotFoundException:找不到文件 - System.IO.FileNotFoundException : Could not find file Xamarin Android System.IO.FileNotFoundException:找不到文件异常 - Xamarin Android System.IO.FileNotFoundException: Could not find file Exception System.IO.FileNotFoundException: '找不到文件 Xamarin Forms - System.IO.FileNotFoundException: 'Could not find file Xamarin Forms 控制台应用程序:System.IO.FileNotFoundException:找不到文件 - Console Application: System.IO.FileNotFoundException: Could not find file .NET 7 System.IO.FileNotFoundException:找不到文件 - .NET 7 System.IO.FileNotFoundException: Could not find file System.IO.FileNotFoundException: 无法加载文件或程序集 C# - System.IO.FileNotFoundException: Could not load file or assembly C# 奇怪的错误:System.IO.FileNotFoundException:无法加载文件或程序集 - Weird Error: System.IO.FileNotFoundException: Could not load file or assembly System.IO.FileNotFoundException: '找不到文件'C:\Program Files (x86)\IIS Express\files'。 - System.IO.FileNotFoundException: 'Could not find file 'C:\Program Files (x86)\IIS Express\files'.'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM