Exemplo n.º 1
0
        private void 新键_Click(object sender, EventArgs e)
        {
            string newdir = DirectoryCore.NewName(filename + "\\" + "新建文件夹");

            //MessageBox.Show(newdir);
            Directory.CreateDirectory(newdir);
            TreeNode node = new TreeNode(Path.GetFileNameWithoutExtension(newdir));

            treeView1.SelectedNode.Nodes.Add(node);
            treeView1.SelectedNode = node;

            重命名_Click(sender, e);
        }
Exemplo n.º 2
0
        private void MoveToRecylebin()
        {
            string        recyclePath1 = DirectoryCore.NewName(recyclepath + "\\" + treeView1.SelectedNode.Text);
            DirectoryInfo di           = new DirectoryInfo(recyclePath1);

            Directory.Move(filename, recyclePath1);

            //只保证移到回收站也有右键菜单
            TreeNode selnode = (TreeNode)treeView1.SelectedNode.Clone();

            recyclebinNode.Nodes.Add(selnode);
            treeView1.SelectedNode.Remove();
            selnode.Text = Path.GetFileNameWithoutExtension(recyclePath1);
        }
Exemplo n.º 3
0
        private void treeView1_DragDrop(object sender, DragEventArgs e)
        {
            #region LISTVIEW 拖拽到TREEVIEW上
            if (e.Data.GetDataPresent(typeof(ListView.SelectedListViewItemCollection).ToString(), false))
            {
                Point    loc       = ((TreeView)sender).PointToClient(new Point(e.X, e.Y));
                TreeNode destNode1 = ((TreeView)sender).GetNodeAt(loc);

                ListView.SelectedListViewItemCollection lstViewColl =
                    (ListView.SelectedListViewItemCollection)e.Data.GetData(typeof(ListView.SelectedListViewItemCollection));

                foreach (ListViewItem lvItem in lstViewColl)
                {
                    string source = filename + "\\" + lvItem.Text;
                    if (!source.EndsWith(".htm"))
                    {
                        source += ".htm";
                    }

                    string dest = rootpath + "\\" + destNode1.FullPath + "\\" + lvItem.Text;
                    if (!dest.EndsWith(".htm"))
                    {
                        dest += ".htm";
                    }

                    if (filename == rootpath + "\\" + destNode1.FullPath)
                    {
                        MessageBox.Show("源文件和目标不能是同一个文件");
                        return;
                    }

                    dest = FileCore.NewName(dest);

                    string html  = File.ReadAllText(source, Encoding.UTF8);
                    string title = FileCore.GetHTMLTitleTag(html);
                    if (title != "")
                    {
                        html = html.Replace(title, Path.GetFileNameWithoutExtension(dest));
                    }

                    File.WriteAllText(source, html, Encoding.UTF8);

                    //移动文件
                    File.Move(source, dest);

                    //移动_attachments
                    string source_attachments = DirectoryCore.Get_AttachmentsDirectory(source);
                    string dest_attachments   = DirectoryCore.Get_AttachmentsDirectory(dest);

                    if (Directory.Exists(dest_attachments.ToLower()))
                    {
                        Directory.Delete(dest_attachments);
                    }

                    if (Directory.Exists(source_attachments.ToLower()))
                    {
                        Directory.Move(source_attachments, dest_attachments);
                    }

                    lvItem.Remove();
                }
            }



            #endregion



            #region TreeView自己的拖拽

            destNode = treeView1.GetNodeAt(treeView1.PointToClient(new Point(e.X, e.Y)));
            string destNodeText = rootpath + "\\" + destNode.FullPath;

            if (selNode != destNode && (selNode.Parent != destNode))
            {
                //文件 拖拽 到文件夹中

                if (File.Exists(filename) && Directory.Exists(destNodeText))
                {
                    string destfile = FileCore.NewName(rootpath + "\\" + destNode.FullPath + "\\" + selNode.Text);
                    if (filename == destfile)
                    {
                        MessageBox.Show("源文件和目标不能是同一个文件");
                        return;
                    }


                    string html  = File.ReadAllText(filename, Encoding.UTF8);
                    string title = FileCore.GetHTMLTitleTag(html);
                    if (title != "")
                    {
                        html = html.Replace(title, Path.GetFileNameWithoutExtension(destfile));
                    }
                    File.WriteAllText(filename, html, Encoding.UTF8);


                    File.Move(filename, destfile);


                    TreeNode selnode = (TreeNode)treeView1.SelectedNode.Clone();
                    destNode.Nodes.Add(selnode);

                    DirectoryInfo di = new DirectoryInfo(destfile);
                    selnode.Text = Path.GetFileName(di.Name);

                    treeView1.SelectedNode.Remove();
                    destNode.Expand();


                    //移动_attachments
                    string source_attachments = DirectoryCore.Get_AttachmentsDirectory(filename);
                    string dest_attachments   = DirectoryCore.Get_AttachmentsDirectory(destfile);

                    if (Directory.Exists(dest_attachments.ToLower()))
                    {
                        Directory.Delete(dest_attachments);
                    }

                    if (Directory.Exists(source_attachments.ToLower()))
                    {
                        Directory.Move(source_attachments, dest_attachments);
                    }
                }

                //文件夹 拖拽 到文件夹中
                if (Directory.Exists(filename) && Directory.Exists(destNodeText))
                {
                    string destpath = DirectoryCore.NewName(rootpath + "\\" + destNode.FullPath + "\\" + selNode.Text);
                    Directory.Move(filename, destpath);

                    //if (selNode.Parent == null)
                    //    treeView1.Nodes.Remove(selNode);
                    //else
                    //    selNode.Parent.Nodes.Remove(selNode);

                    TreeNode selnode = (TreeNode)treeView1.SelectedNode.Clone();
                    destNode.Nodes.Add(selnode);
                    DirectoryInfo di = new DirectoryInfo(destpath);
                    selnode.Text = Path.GetFileNameWithoutExtension(di.Name);

                    treeView1.SelectedNode.Remove();
                    destNode.Expand();
                }
            }
            #endregion
        }