我正在使用 Visual Studio 2010
开发网站。我正在尝试将文件保存在路径中。它在本地主机上运行良好。
但是相同的代码在 IIS 中不起作用。显示如下错误
Exception Details: System.IO.DirectoryNotFoundException: Could not find a part of the path 'C:\Inetpub\wwwroot\Vendor\cn.jpg'.
Could not find a part of the path 'C:\Users\shashank\Desktop\ab.csv'.
代码如下:
protected void btnImportFile_Click(object sender, EventArgs e)
{
sArReportText = File.ReadAllText(txtFilePath.Text.Trim());
// Set the report Properties to insert Report information
SetProperties();
}
最佳答案
您可能也遇到了我的情况:目录名称包含一些不寻常的字符。就我而言,
Could not find a part of the path 'C:\Web\metBoot\wild iis\DigiCert© Certificate Utility for Windows_files'.
版权标志就是问题所在。
因此使用来自 Obtaining the short 8.3 filename from a long filename 的概念,我首先将我的路径转换为短格式,然后使用它来获取我的文件列表。
StringBuilder sf = new StringBuilder(300);
int n = GetShortPathName(sourceFolder, sf, 300);
if (0 == n)
{
tk.write(Marshal.GetLastWin32Error().ToString());
continue;
}
...
IEnumerable<string> fileGroup = Directory.EnumerateFiles(sf.ToString(), ext);
关于c# - 为什么我会收到 "Could not find a part of the path"异常?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18740564/