pistacchio
pistacchio

Reputation: 58883

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

Upvotes: 2

Views: 1055

Answers (1)

dommer
dommer

Reputation: 19810

Have you tried:

Dim b As Bitmap = New Bitmap(HttpContext.Current.Server.MapPath("~/img.bmp"))

Upvotes: 10

Related Questions