Книга: C# 2008 Programmer

Removing a Directory

Removing a Directory

To remove (delete) a directory, a user first selects the folder to delete and then clicks the Remove Folder button. To delete a directory, you call the PerformWebRequest() helper function you defined earlier. This is accomplished with the Remove Folder button:

//---Remove a folder---
private void btnRemoveFolder_Click(object sender, EventArgs e) {
 if (TreeView1.SelectedNode.ImageIndex == ico_PHOTO) {
  MessageBox.Show("Please select a folder to delete.");
  return;
 }
 try {
  string FullPath =
   Properties.Settings.Default.FTP_SERVER +
   TreeView1.SelectedNode.FullPath.Substring(1).Replace("r", "");
  //---remove the folder--- 
  FtpWebResponse ftpResp =
   PerformWebRequest(FullPath, WebRequestMethod.RemoveDirectory);
  //---delete current node---
  TreeView1.SelectedNode.Remove();
  //---update the statusbar---
  ToolStripStatusLabel1.Text =
   ftpResp.StatusDescription.Replace("rn", string.Empty);
 } catch (Exception ex) {
  MessageBox.Show(ex.ToString());
 }
}

If a directory is not empty (that is, if it contains files and subdirectories), the deletion process will fail. The user will have to remove its content before removing the directory. 

Оглавление книги


Генерация: 0.031. Запросов К БД/Cache: 0 / 0
поделиться
Вверх Вниз