i have relative path of an image as
~/image/noimage.jpg
i wants to read byte array to save in database if that organization's logo 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 am setting this path to asp image control then it is working fine.
logo.ImageUrl = "~/image/noimage.jpg";
any idea ?????
File.ReadAllBytes
is not an asp.net api, so the leading ~ means nothing to it. Instead, try:
string path = HttpContext.Current.Server.MapPath("~/image/noimage.jpg");
photo = File.ReadAllBytes(path);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With