Книга: 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.
- Creating a New Directory
- Uploading Photos
- Deleting a Photo
- Testing the Application
- Безопасность внешних таблиц. Параметр EXTERNAL FILE DIRECTORY
- ТМР DIRECTORY
- EXTERNAL FUNCTION DIRECTORY
- 5.1.2. The Directory Server Interface
- Directory Permissions
- Initializing the Data Directory in PostgreSQL
- Populating Your Directory
- Listing Files in the Current Directory with ls