質問

protected void Button1_Click(object sender, EventArgs e)
{
    try
    {
        if (FileUpload1.HasFile)
        {
            string FileName = Path.GetFileName(FileUpload1.PostedFile.FileName);
            string path = Server.MapPath("~//Images//" + FileName);
            FileUpload1.SaveAs(path);
            string imagepathsource = path;
            string imagepathdest = @"D:\\" + Session["brandname"].ToString() + "\\" + Seasonfolders.SelectedItem.Text + "\\" + stylefolders.SelectedItem.Text + "\\Images\\" + FileName;
            File.Move(imagepathsource, imagepathdest);

            uploadedimage.ImageUrl = "D://" + Session["brandname"].ToString() + "//" + Seasonfolders.SelectedItem.Text + "//" + stylefolders.SelectedItem.Text + "//Images//" + FileName;
        }
    }

uploadedimage is a ImageButton where I need to display the image using imageurl with that link. The image is not displaying and no error.. I could see when the above code gets execute the page is getting refreshed? What code can be added in this ??

役に立ちましたか?

解決

ImageUrl needs an URL.

So instead of assigning it with a local file name on disk, use something like this (where ~ stands for 'application root folder':

uploadedimage.ImageUrl = "~/Images/yourImage.png"

You have to supply it with:

  • An image inside your application root folder;
  • An URL that is catched by a HttpHandler, that generates / loads the image from a different location (a little harder to do, but if you need to load from another location then inside application root, this is the best option).
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top