【问题标题】:Image upload require to include image into solution each time图片上传需要每次都将图片包含在解决方案中
【发布时间】:2013-02-24 14:27:38
【问题描述】:

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

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。 我不想包含每张图片。有什么办法可以解决这个问题。感谢您的帮助。

【问题讨论】:

  • 你的问题不清楚。您能否重新制定您想要实现的目标?
  • 先生,实际上在上传后我需要将该图像包含到 JQueryImage 文件夹中。图像显示到文件夹中,但我必须右键单击并包含在其中。
  • 为什么您的工作解决方案文件位于您的生产目录中?听起来你的工作方式很奇怪。

标签: c# asp.net image-upload


【解决方案1】:
 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;

这是我使用的最终代码。现在可以了。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-16
    • 2018-06-07
    • 1970-01-01
    • 2019-06-19
    • 1970-01-01
    • 2015-07-20
    相关资源
    最近更新 更多