Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load an image server-side in ASP.NET?

I'm trying to load an image that is in the root dir of my project:

Dim b As Bitmap = New Bitmap("img.bmp")

but it doesn't seem to find the file.

I've tried various combinations like ~img.gif, /img.gif, \img.gif, ~/img.gif etc, but none seems to work. How to access the "current directory on server" in ASP.NET?

Thanks

like image 743
pistacchio Avatar asked Dec 29 '25 12:12

pistacchio


1 Answers

Have you tried:

Dim b As Bitmap = New Bitmap(HttpContext.Current.Server.MapPath("~/img.bmp"))
like image 79
dommer Avatar answered Dec 31 '25 02:12

dommer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!