Книга: C# 2008 Programmer
Creating a New Directory
Creating a New Directory
The user can create a new directory on the FTP server by clicking the Create Folder button. To create a new directory, select a node (by clicking on it) to add the new folder, and then call the PerformWebRequest()
helper function you defined earlier. This is accomplished by the Create Folder button:
//---Create a new folder---
private void btnCreateFolder_Click(object sender, EventArgs e) {
//---ensure user selects a folder---
if (TreeView1.SelectedNode.ImageIndex == ico_PHOTO) {
MessageBox.Show("Please select a folder first.");
return;
}
try {
//---formulate the full path for the folder to be created---
string folder = Properties.Settings.Default.FTP_SERVER +
TreeView1.SelectedNode.FullPath.Substring(1).Replace("r", "") +
@"/" + txtNewFolderName.Text;
//---make the new directory---
FtpWebResponse ftpResp =
PerformWebRequest(folder, WebRequestMethod.MakeDirectory);
ftpResp.Close();
//---refresh the newly added folder---
RefreshCurrentFolder();
//---update the statusbar---
ToolStripStatusLabel1.Text =
ftpResp.StatusDescription.Replace("rn",string.Empty);
} catch (Exception ex) {
MessageBox.Show(ex.ToString());
}
}
When a new folder is created, you update the TreeView control to reflect the newly added folder. This is accomplished by the RefreshCurrentFolder()
function:
private void RefreshCurrentFolder() {
//---clears all the nodes and...---
TreeView1.SelectedNode.Nodes.Clear();
//---...create the nodes again---
BuildDirectory(TreeView1.SelectedNode);
}
- Mounting the New Partition and Populating It with the Relocated Files
- Безопасность внешних таблиц. Параметр EXTERNAL FILE DIRECTORY
- ТМР DIRECTORY
- EXTERNAL FUNCTION DIRECTORY
- State NEW packets but no SYN bit set
- 2. How to Apply These Terms to Your New Programs
- Creating CDs from the Command Line
- Операция new
- Creating and Deleting Device Objects
- Creating a Delegate
- 5.1.2. The Directory Server Interface
- Creating a Root Password and User Accounts