图像上传需要每次将图像包含到解决方案中

时间:2013-02-24 14:27:38

标签: c# asp.net image-upload

我需要上传图片。我的编码如下:

string filename = "";
            string FilePath = "";
            filename = Path.GetFileName(FileImage.FileName);
            FilePath = Server.MapPath("./JQueryImages");
            string destPath = Path.Combine(FilePath, filename);
            FileImage.PostedFile.SaveAs(destPath);
            ViewState["ImagePath"] = destPath.ToString();
            ImgUploaded.ImageUrl = destPath;
            LblUploadMsg.Text = "Image uploaded successfully";
            LblUploadMsg.ForeColor = Color.Green;

图片进入文件夹JQueryImages,但我有一个图片控件ImgUploaded,在加载时不会显示图片。当我检查我的解决方案文件夹图像时,没有加载。上传后我需要to include each image。 我不想包含每张图片。可以解决这个问题。谢谢你的帮助。

1 个答案:

答案 0 :(得分:0)

 string filename = "";
            string FilePath = "";
            filename = Path.GetFileName(FileUpload1.FileName);
            FilePath = Server.MapPath("./JQueryImages");
            string destPath = Path.Combine(FilePath, filename);
            FileUpload1.PostedFile.SaveAs(destPath);
            ViewState["ImagePath"] = destPath.ToString();
            Image1.ImageUrl = "~/JQueryImages/" + filename;
            Label1.Text = "Image uploaded successfully";
            Label1.ForeColor = Color.Green;

这是我用过的最终代码。它现在有效。