private FileExplorerItem createFileNode(FileInfo info) { FileExplorerItem itemExisting = getFileNode(info.FullName); if (itemExisting != null) { itemExisting.FileInfo = info; itemExisting.Text = info.Name; this.treeView1.Sort(); return itemExisting; } else { FolderExplorerItem folderParent = this.getFolderNode(this.rootNode, info.DirectoryName); if (folderParent != null) { FileExplorerItem item = new FileExplorerItem(info); folderParent.Nodes.Add(item); this.treeView1.Sort(); return item; } return null; } }
private void getFiles(DirectoryInfo parentDir, FolderExplorerItem nodeToAddTo) { FileExplorerItem aNode; FileInfo[] files = parentDir.GetFiles(); foreach (FileInfo file in files) { aNode = this.getFileNode(file.FullName); if (aNode == null) { aNode = new FileExplorerItem(file); nodeToAddTo.Nodes.Add(aNode); } } }
private void addFilesBt_Click_1(object sender, EventArgs e) { if (this.mainForm.CurrentProject != null && this.treeView1.SelectedNode != null && this.treeView1.SelectedNode is FolderExplorerItem) { try { FolderExplorerItem currentFolder = this.treeView1.SelectedNode as FolderExplorerItem; OpenFileDialog openF = new OpenFileDialog(); openF.Multiselect = true; openF.Filter = "All files type (*.*)|*.*"; if (openF.ShowDialog() == DialogResult.OK) { int count = 0; for (int i = 0; i < openF.FileNames.Length; i++) { string filename = openF.FileNames[i]; if (File.Exists(filename)) { File.Copy(filename, currentFolder.FolderInfo.FullName + "\\" + openF.SafeFileNames[i], true); FileExplorerItem newItem = new FileExplorerItem(new FileInfo(currentFolder.FolderInfo.FullName + "\\" + openF.SafeFileNames[i])); currentFolder.Nodes.Add(newItem); count++; } else { MessageBox.Show("The file " + filename + " does not exist!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } this.treeView1.Sort(); if (count > 1) MessageBox.Show(count + " files have been successfully imported!", "Importation succeed!", MessageBoxButtons.OK, MessageBoxIcon.Information); else MessageBox.Show(count + " file has been successfully imported!", "Importation succeed!", MessageBoxButtons.OK, MessageBoxIcon.Information); } } catch (Exception ex) { MessageBox.Show("Error during file importation!\n" + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }