Книга: C# 2008 Programmer

Deleting a Photo

Deleting a Photo

To delete a photo, the user first selects a photo to delete and then you call the PerformWebRequest() helper function you have defined earlier:

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

Once the photo is removed from the FTP server, you also need to delete its node in the TreeView control.

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


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