我有一个图像的相对路径

~/image/noimage.jpg

如果该组织的徽标不在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;
    }

当我将此路径设置为ASP图像控制时,它工作正常。
logo.ImageUrl = "~/image/noimage.jpg";

任何想法 ?????

最佳答案

File.ReadAllBytes不是asp.net api,因此〜对此毫无意义。相反,请尝试:

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

关于c# - 图像到C#中字节数组的相对路径,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19476299/

10-09 15:31
查看更多