在asp.net中显示图像

本文关键字:显示图 图像 显示 asp net | 更新日期: 2023-09-27 17:58:56

在下面的代码中,我有一个文档,我想检查它是否是jpeg格式,如果是,它应该显示图像。请帮我做这个。

public string strName = "Sample";
public string strFolder = "Documents";
if (!IsPostBack)
{
   var SearchDoc = (SearchDoc)Session["Documentname"];
   string Imgdocname = SearchDoc.DocumentName;
   string fileExt = System.IO.Path.GetExtension(Imgdocname);
   fileExt = fileExt.ToLower();
   if (fileExt == ".jpeg" || fileExt == ".jpg")
   {
      docimg.ImageUrl = "C:''Search''" + strName + "''" + strFolder + "''" + Imgdocname;
      docimg.Visible = true;
      Response.Write("Success");
   }
   else
   {
      Response.Write("fail");
   }
}
<asp:Image ID="docimg" runat="server" />

在asp.net中显示图像

试试这个代码

string fileExt = System.IO.Path.GetExtension(Imgdocname);
fileExt = fileExt.ToLower();
if (fileExt == ".jpeg" || fileExt == ".jpg")
{
   docimg.ImageUrl = @"C:''Search''" + strName + "''" + strFolder + "''" + Imgdocname;
}
else
{
   Response.Write("fail");
}
<asp:Image ID="docimg" runat="server" />