Question

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 ??

Était-ce utile?

La solution

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).
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top