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

6
  • Do you get an exception? Commented May 15, 2014 at 10:20
  • 1
    ASP.NET controls will not allow absolute paths. It should with wrt server url Commented May 15, 2014 at 10:22
  • @ThanosMarkou No Exceptions ... Just executes with no output ... Commented May 15, 2014 at 10:32
  • @Bharadwaj So how to access the filepath from E: to D: Commented May 15, 2014 at 10:32
  • @Sriram Flies which you want to display on a page to user, should be under application folder, if you want files to open and process in code, then those can be accessed through absolute path. Commented May 15, 2014 at 10:37

1 Answer 1

2

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).
Sign up to request clarification or add additional context in comments.

1 Comment

I stuck with accessing folders... I kept my application in folders like this .../Folder1/Folder2/Folder3/Folder4/Application... How to map again to the folder1... its showing path is not valid

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.