hi i search lot on this but i didn't get any solution so i thought i should ask here my question is quite different i have a grid-view in which i have an image button to delete department
Now according to my application when i create department a folder with that department name will create and in my upload images page user can user those department to save images in those department folder with and their path store in the database.
upload image page.cs
protected void btnSubmit_Click1(object sender, EventArgs e)
{
string DepartmentID = ddlDepartment.SelectedValue;
string Description = tbImageName.Text.Trim();
string Priority = lblPriority.Text;
string imgName = fileuploadimages.FileName.ToString();
string imgPath = "Images/Departments/" + "" + ddlDepartment.SelectedValue + "/";
bool IsExists = System.IO.Directory.Exists(Server.MapPath(imgPath));
if (!IsExists)
System.IO.Directory.CreateDirectory(Server.MapPath(imgPath));
fileuploadimages.SaveAs(Server.MapPath(imgPath + imgName));
con.Open();
SqlCommand cmd = new SqlCommand("Insert into Images(ImageName,Description,Path,Priority,DepartmentID) values(@ImageName,@Description,@Path,@Priority,@DepartmentID)", con);
cmd.Parameters.AddWithValue("@ImageName", imgName);
cmd.Parameters.AddWithValue("@Description", Description);
cmd.Parameters.AddWithValue("@Path", imgPath + imgName);
cmd.Parameters.AddWithValue("@Priority", Priority);
cmd.Parameters.AddWithValue("@DepartmentID", DepartmentID);
cmd.ExecuteNonQuery();
con.Close();
tbImageName.Text = string.Empty;
Response.Redirect(Request.RawUrl);
}
n department_master page
When user click on delete image button a confirmation message box will appear to ask yes or no if yes then department delete from the database with folder and images now that part is done by me
for this code i used is department.aspx.cs:
protected void gvDetails_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
string id = gvDetails.DataKeys[e.RowIndex].Values["DepartmentID"].ToString();
con.Open();
SqlCommand cmd = new SqlCommand("Select * from Department_Master where DepartmentID=" + id, con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataTable dt = ds.Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
string imgPath = "Images/Departments/" + "" + dt.Rows[i]["DepartmentID"] + "/";
bool IsExists = System.IO.Directory.Exists(Server.MapPath(imgPath));
if (IsExists)
System.IO.Directory.Delete(Server.MapPath(imgPath), true);
}
con.Close();
con.Open();
SqlCommand cmd1 = new SqlCommand("Delete from Images where DepartmentID=" + id + "; delete from Department_Master where DepartmentID=" + id, con);
int result = cmd1.ExecuteNonQuery();
con.Close();
if (result == 1)
{
BindDetails();
lblresult.ForeColor = Color.Red;
lblresult.Text = id + " details deleted successfully";
}
BindDetails();
}
<asp:ImageButton ID="imgbtnDelete" CommandName="Delete" Text="Edit" runat="server" ImageUrl="~/Images/delete.jpg" ToolTip="Delete" Height="20px" Width="20px" önClientClick=" return confirm('Are you sure you want to delete');"/>
now what i want is when user click on image button a message box comes with yes or no and when user click on yes to delete department another confirmation box will appear to ask whether they want to save those image or not and if they click on yes then show them the option where they can save those images and if no then delete department with folder and images just like the department.aspx.cs page code