Code To upload Your Image to folder
YourFunctionToUploadImage()
{
//Check FileUpload controll has File Or not
if (ImageFileUploadControll.HasFile)
{
string fileExtention = System.IO.Path.GetExtension(ImageFileUploadControll.FileName);
//Check For Valid Extension
if (fileExtention.ToLower() != ".jpg" && fileExtention.ToLower() != ".jpeg" && fileExtention.ToLower() != ".png")
{
lblUploadstatus.Text = "Invalid File Choose .jpg/.jpeg/.png/.gif";
}
else
{
//check if file already Exists in Folder
if (File.Exists(Server.MapPath("~/Folder_Name/" + ImageFileUploadControll.FileName)))
{
lblUploadstatus.Text = "File Already Exists. Rename filename";
}
else
{
//To Save Image To your Specific Location.
//srever.mappath takes us to Folder which containing our application
ImageFileUploadControll.SaveAs(Server.MapPath("~/Folder_Name/" + ImageFileUploadControll.FileName));
lblUploadstatus.Text = "Upload Status : File Uploaded Successfully";
}
}
}
else
{
lblUploadstatus.Text = "Please Select File";
}
}
Code To Retrive All Images form Folder and display in image_control you can use
PageLoadEvent()
{
//use DirectoryInfo to get all imageFile's Information
DirectoryInfo dir = new DirectoryInfo(Server.MapPath("~/Folder_Name/"));
FileInfo[] fi = dir.GetFiles();
//Now you just need to create new image control each time and add ImageUrl to it
foreach(FileInfo f in fi)
{
string imageUrl = f.ToString();
Image img = new Image();
img.ImageUrl = "~/Folder\_Name/"+"imageUrl";
}
}
Hope This Help
Pratik Bhuva --------------- The night is darkest just before the dawn. And I promise you, the dawn is coming