Deepak Sharma

Deepak Sharma

  • NA
  • 143
  • 11.1k

Deleting photos from Gallary

Mar 8 2017 5:07 AM
Hi,
 
I am facing problem while deleting a photos from gallary.
I have created a gallary and there is a option for upload images in particular path not in a database.and i want option for select and delete photos.
 
Coading of upload option and delete option
protected void Page_Load(object sender, EventArgs e)
{
uploadimage();
}
protected void Button1_Click1(object sender, EventArgs e)
{
if (FileUpload1.HasFile)
{
string fileName = FileUpload1.FileName;
FileUpload1.PostedFile.SaveAs(Server.MapPath("~/Images/" + fileName));
}
Response.Redirect("~/Upload.aspx");
}
private void uploadimage()
{
foreach (string strFileName in Directory.GetFiles(Server.MapPath("~/Images/")))
{
ImageButton imageButton = new ImageButton();
FileInfo fileInfo = new FileInfo(strFileName);
imageButton.ImageUrl = "~/Images/" + fileInfo.Name;
imageButton.Width = Unit.Pixel(100);
imageButton.Height = Unit.Pixel(100);
imageButton.Style.Add("Padding", "10px");
imageButton.Click += new ImageClickEventHandler(imageButton_Click);
Panel1.Controls.Add(imageButton);
}
}
void imageButton_Click(object sender, ImageClickEventArgs e)
{
Response.Redirect("~/Photosview.aspx?ImageURL=" + ((ImageButton)sender).ImageUrl);
}
protected void Button2_Click(object sender, EventArgs e)
{
string path = Server.MapPath(@"Images\");
string imgurl = path + "/Images/a.jpg";
try
{
FileInfo TheFile = new FileInfo(imgurl);
if (TheFile.Exists)
{
File.Delete(imgurl);
}
else
{
Bitmap bmp = new Bitmap(2, 2);
bmp.Save(imgurl, System.Drawing.Imaging.ImageFormat.Jpeg);
bmp.Dispose();
}
Label1.Text = "Success";
}
catch (Exception ex)
{
Label1.Text = ex.Message;
}
 

Answers (2)