public void CopyElement(string destpath) { if (ListBoxOfElements.SelectedItem is FileView) { MyFile filetocopy = (ListBoxOfElements.SelectedItem as FileView).GetFile; filetocopy.Copy(destpath); } else if (ListBoxOfElements.SelectedItem is DirectoryView) { MyDirectory directorytocopy = (ListBoxOfElements.SelectedItem as DirectoryView).GetDirectory; directorytocopy.Copy(destpath); } }