Книга: 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.");
 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);
  //---refresh the newly added folder---
  //---update the statusbar---
  ToolStripStatusLabel1.Text =
 } catch (Exception ex) {

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...---
 //---...create the nodes again---

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

Генерация: 1.110. Запросов К БД/Cache: 3 / 1
Вверх Вниз