天天看點

[C#]讀取目前項目中的圖檔Image.FromFile

問題:

不會使用Image.FromFile(),看到網上的答案都是寫filepath在伺服器上的,沒有寫怎麼讀取目前解決方案下的圖檔的路徑,寫相對路徑找不到。

System.IO.FileNotFoundException

解決方法:

Image.FromFile(Server.MapPath("~/Content/imgs/defaultImg.jpeg"))
           

其中:

./目前目錄

/網站主目錄

../上層目錄

~/網站虛拟目錄