I recently came across an article on how upload and display image with FileUpload control.
What was not clear to me is the file path. I just need to click on the image and select an image from my local machine and then the selected image will be displayed inside the image control.
I already how this is done in JavaScript, I need to learn how it can be done in C#
protected void UploadFile(object sender, EventArgs e)
{
string folderPath = Server.MapPath("~/Files/");
//Check whether Directory (Folder) exists.
if (!Directory.Exists(folderPath))
{
//If Directory (Folder) does not exists Create it.
Directory.CreateDirectory(folderPath);
}
//Save the File to the Directory (Folder).
FileUpload1.SaveAs(folderPath + Path.GetFileName(FileUpload1.FileName));
//Display the Picture in Image control.
Image1.ImageUrl = "~/Files/" + Path.GetFileName(FileUpload1.FileName);
}