Reputation: 939
I am working on WPF. I developed a WPF application in which the user can create and delete folders. Creation of folder is working fine, but in deletion there are issues in accessing the folder, even the drive. By following the steps mentioned below, I was able to change the owner and the permissions. But it still doesn't work:
Code:
if (DXMessageBox.Show ("Are You Sure, you Want to Delete?", "Delete Item-Confirmation", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
{
try
{
int ID = (grid.SelectedItem as Name).PK_ID;
string folderpath = @"F:/Delete/" +(grid.SelectedItem as Name).Name1;
string foldername = (grid.SelectedItem as Name).Name1;
File.Delete(folderpath);
if (!Directory.Exists(folderpath))
{
SqlConnection con = new SqlConnection(connection_string);
con.Open();
SqlCommand comm = new SqlCommand("Delete From Names where PK_ID=" + ID + ";", con);
comm.ExecuteNonQuery();
con.Close();
MessageBox.Show(folderpath);
Refresh();
}
}
catch (Exception ex)
{
DXMessageBox.Show(ex.Message.ToString());
}
}
Upvotes: 0
Views: 512
Reputation: 939
I want to delete a folder, so i useDirectory.Delete(folderpath);
instead of using File.Delete(folderpath);
Thank you everyone specially to Rahul :)
Upvotes: 2