Relative image path to byte array in C #

i has a relative image path as

~/image/noimage.jpg 

I need to read an array of bytes to be stored in the database if the logo of this organization is not in db

 public byte[] org_logo(int myOrgId) { byte[] photo ; var context = new mp_repositoryEntities(); var query = from o in context.organizations where o.organization_id == myOrgId select o.logo; photo = query.FirstOrDefault<byte[]>(); if (photo == null) { photo = File.ReadAllBytes("~/image/noimage.jpg"); } return photo; } 

when i set this path in asp control then it works fine.

 logo.ImageUrl = "~/image/noimage.jpg"; 

any idea ?????

+7
c # image
source share
1 answer

File.ReadAllBytes not an asp.net api, so the presenter ~ means nothing to it. Try instead:

 string path = HttpContext.Current.Server.MapPath("~/image/noimage.jpg"); photo = File.ReadAllBytes(path); 
+16
source share

All Articles