Search code examples
c#asp.neturlcode-behind

Get Image from code behind


How can I get an image stored in a application folder from code behind?

I need to convert an image in byte[]. So I do this :

        MemoryStream stream = new MemoryStream();            
        System.Drawing.Image.FromFile(ResolveUrl("~/Icons/CMJN.png")).Save(stream,System.Drawing.Imaging.ImageFormat.Png);
        var foo = stream.ToArray();

But It seems he never find the image with the resolve URL. I'm in the page load of a page..


Solution

  • Use Server.MapPath to get the physical file path.

    Server.MapPath("~/Icons/CMJN.png")