ASP.NET design network hard disk delete folder implementation code

  • 2020-05-17 05:16:47
  • OfStack

Interface layout

There is a "delete" button in the main interface design, whose (ID) is btnDelete. After the user selects the item to delete in the directory browse, click the button to complete the deletion.

Code implementation

Double-click the "delete" button in the "design" panel to add the event handler as follows:
 
private void BtnDelete_Click(object sender, System.EventArgs e) 
{ 
 DeleteThings(FileList.SelectedItem.Text); 
} 

private void DeleteThings(string FullPath) 
{ 
 if(FullPath.IndexOf(".")>0) // Delete the file  
 { 
  File.Delete(FullPath); 
  LoadDir(CurrentPath); // Reload the current directory  
 } 
 else // Delete the directory  
 { 
  Directory.Delete(FullPath); 
  LoadDir(CurrentPath); // Reload the current directory  
 } 
} 

The first thing to check when deleting is whether a file or folder is selected. If it is a file, the File.Delete () method is called. If not, the Directory.Delete () method is called. After successful deletion, the LoadDir() method is called to display the changed contents of the directory.

Related articles: