如何使用c#使用保存在数据库中的url路径检索图像?

时间:2018-06-14 21:10:30

标签: c# ado.net entity-framework-6

我需要使用url路径从服务器检索图像。我正在使用生成pdf报告的控制台应用程序,我正在使用实体模型从数据库中检索数据并使用html创建报告。

我通过从服务器获取urlpath并将其放入 ex:

string html = "<img src='" + inspector_Signature + "'>";

会起作用,它只是空白。

这是我的疑问:

using (var context = new dbName_pdf.dbName_dbEntities())
        {
            var db_data= (from lo in context.tbl_loans
                         join doc in context.tbl_docinfo on lo.idDocInfo equals doc.idDocInfo
                         join insp in context.tbl_inspections on lo.idLoan equals insp.idLoan
                         join p1 in context.tbl_pir01 on lo.idLoan equals p1.idLoan
                         join pho in context.tbl_photos on lo.idLoan equals pho.idLoan
                         join me in context.tbl_members on insp.idMember equals me.id
                         join sig in context.tbl_inspector_signature on me.id equals sig.idMember
                         join p2 in context.tbl_pir02 on lo.idLoan equals p2.idLoan
                         join cm in context.tbl_comments_inspections on lo.idLoan equals cm.idLoan
                         where insp.StatusInspections == 3 && lo.idLoan == 5
                         orderby cm.CommentDateCreated descending
                         select new
                         {
                             Loan = lo,
                             DocInfo = doc,
                             Inspection = insp,
                             pir1 = p1,
                             pir2 = p2,
                             photos = pho,
                             members = me,
                             signature = sig,
                             inspection_comments = cm
                         });

我用来存储图片的字符串:

string inspector_Signature = db_data.First().signature.locationSign;

注意:我搜索了一个解决方案,但我发现的所有问题都涉及MVC / ASP.net,但这些问题并没有适用于我的情况。

1 个答案:

答案 0 :(得分:0)

对于未来的人来说,这就是答案。

我只需要添加完整的url路径。

string inspector_Signature = "http://www.webpage.com/" + db_data.First().signature.locationSign;

现在,当我将其添加到我的html字符串时,图像呈现:

string html = "<img src='" + inspector_Signature + "' width='180' height='50'>";