[英]Uploaded image doesn't show in image control in asp.net
当我上传存储在文件夹中的图像但没有显示在图像控制中。 怎么解决这个? 我在更新面板中使用文件上传和图像控制。
private void StartUpLoad()
{
string imgName = fuimage.FileName;
int imgSize = fuimage.PostedFile.ContentLength;
string ext = System.IO.Path.GetExtension(this.fuimage.PostedFile.FileName);
if (fuimage.PostedFile != null && fuimage.PostedFile.FileName != "")
{
if (imgSize > 2097151)
{
lblimgname.Text = "alert('File is too big.')";
}
if (ext.ToUpper().Trim() != ".JPG" && ext.ToUpper() != ".PNG" && ext.ToUpper() != ".JPEG")
{
lblimgname.Text = "alert('Please choose only .jpg, .png and .jpeg image types!')";
}
else
{
string fileName = fuimage.FileName.ToString();
string uploadFolderPath = "~/staff_image/";
string filePath = HttpContext.Current.Server.MapPath(uploadFolderPath);
fuimage.SaveAs(filePath + "\\" + fileName);
imgstaff.ImageUrl = "~/Event_Image/" + fuimage.FileName.ToString();
lblimgname.Text = fuimage.FileName.ToString();
Response.Write("Image Saved Successfully!");
}
}
}
好的,请检查这两行:
string uploadFolderPath = "~/staff_image/";
和这个 :
imgstaff.ImageUrl = "~/Event_Image/" + fuimage.FileName.ToString();
所以基本上图像上传到文件夹“staff_image”但稍后你在“Event_Image”文件夹中显示/显示它,所以上传的图像不存在于“Event_Image”位置!
所以在这一行做出这样的改变:
imgstaff.ImageUrl = "~/staff_image/" + fuimage.FileName.ToString();
我已经对它进行了测试,现在它的工作正常并且从该位置正确显示图像。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.