在Visual Studio 2015上运行项目时,当我尝试阅读PDF时,它给了我以下错误;System.IO.File.ReadAllBytes访问被拒绝的路径
访问路径'E:\ FILE \ FILEUPLOAD \ InnerFile \ File'被拒绝。
功能界定及
var cd = new System.Net.Mime.ContentDisposition { FileName = "PDF.pdf", Inline = true };
string contentType = MimeMapping.GetMimeMapping("PDF.pdf");
Response.AppendHeader("Content-Disposition", cd.ToString());
var innerPath = "InnerFile/File" ;
FileInfo fi = new FileInfo(PDFUploadRootPath + innerPath + "/PDF.pdf");
byte[] bytes = System.IO.File.ReadAllBytes(PDFUploadRootPath + innerPath);
return File(bytes, contentType);
注:
- 给予充分的权限用户
- 物理文件存在
我不明白该怎么做,请帮忙!
不要在处理像这样的路径时使用字符串连接,新的FileInfo(PDFUploadRootPath + innerPath +“/PDF.pdf”);使用Path.Combine'''。我看到你有正斜杠'''''''不反斜杠 - 假设你在Windows上运行,它是不合适的路径分隔符。 –
是m在Windows上运行它...检查'fi.Exists'时找到文件。所以它的路径没有问题,在阅读@MarcinZablocki时给出错误 –
如果你的意图是从路径“PDFUploadRootPath + innerPath +”/PDF.pdf“'''读取文件,那么你不这样做在下一行:'''System.IO.File.ReadAllBytes(PDFUploadRootPath + innerPath)'''。 –