bAN
bAN

Reputation: 13825

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..

Upvotes: 0

Views: 683

Answers (2)

huMpty duMpty
huMpty duMpty

Reputation: 14460

Try adding Server.MapPath

System.Drawing.Image.FromFile(Server.MapPath("~/Icons/CMJN.png")).Save(stream,System.Drawing.Imaging.ImageFormat.Png);

Upvotes: 1

Lloyd
Lloyd

Reputation: 2932

Use Server.MapPath to get the physical file path.

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

Upvotes: 2

Related Questions