簡體   English   中英

Server.MapPath 在 ASP.net MVC 中找不到路徑的一部分

[英]Server.MapPath Could not find a part of the path in ASP.net MVC

我有一個幻燈片,可以將本地文件夾中的圖像顯示在我的 Site.Master 頁面中。

所以我用了:

FileInfo[] files = new DirectoryInfo(Server.MapPath("~" + "/path/blahblah/")).GetFiles();

當我在本地運行項目時,它對我來說很好用,但現在我改變了我的項目拋出端口http://195.155.10.521:8081 ,然后它有一個錯誤Could not find a part of the path 'D:\\path\\blahblah\\'

感謝任何人可以給我的任何幫助!

托管站點的端口號對於Server.MapPath方法並不重要。 因此,嘗試拆分方法調用以更輕松地識別問題:

var path = Server.MapPath("~/path/blahblah/");
var di = new DirectoryInfo(path);
var files = di.GetFiles();

如果您收到的錯誤消息是Could not find a part of the path 'D:\\path\\blahblah\\'那么這可能意味着您的服務器上不存在D:\\path\\blahblah\\文件夾。

 var path = Server.MapPath("~/Reproting/Cashstatement.pdf");
 byte[] FileBytes = System.IO.File.ReadAllBytes(path);
 return File(FileBytes, "application/pdf");

暫無
暫無

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

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