//重命名文件 private void winTextBox1_LostFocus(object sender, EventArgs e) { //RENAME //if (fileListView1.listView1.SelectedItems.Count == 1 // && File.Exists(fileListView1.selfilename)) string _htm = ".htm"; if (File.Exists(FullFileName)) { string source = FullFileName; string dest = Path.GetDirectoryName(source) + "\\" + winTextBox1.Text; if (!dest.EndsWith(_htm)) { dest += _htm; } if (!File.Exists(dest)) { string source_attachments = DirectoryCore.Get_AttachmentsDirectory(source); string dest_attachments = DirectoryCore.Get_AttachmentsDirectory(dest); string html = htmEdit1.DocumentText; string title = FileCore.GetHTMLTitleTag(html); if (title != "") { html = html.Replace(title, winTextBox1.Text); } File.WriteAllText(source, html, Encoding.UTF8); File.Move(source, dest); //移动_attachments if (Directory.Exists(source_attachments)) { Directory.Move(source_attachments, dest_attachments); } htmEdit1.htmlfilename = dest; FullFileName = dest; if (filelistview1 != null) { filelistview1.Refresh2(); } UpdateToolTips(); } } }
/// <summary> /// TXTY文件转换成HTML /// </summary> /// <param name="textfile">@"D:\Administrator\Desktop\123.txt"</param> /// <param name="htmlfile">@"D:\Administrator\Desktop\123.html"</param> /// <returns></returns> private bool ConvertTextFileToHtmlFile(string textfile, string htmlfile) { try { string text = HtmlClass.TextToHtml(File.ReadAllText(textfile, Encoding.Default)); string title = FileCore.GetHTMLTitleTag(text); if (title != "") { text = text.Replace(title, Path.GetFileNameWithoutExtension(textfile)); } string html = string.Format("<html><head><title>{0}</title></head><body style=\"margin: 5px\">{1}</body></html>", title, text); File.WriteAllText(htmlfile, html, Encoding.UTF8); successCount++; return(true); } catch (Exception ex) { exceptionText = ex.Message; errorCount++; return(false); } }
private void ToolStripMenuItems_Click(object sender, EventArgs e) { switch (((ToolStripMenuItem)sender).Name) { case "OpenWithNewTab1": OnOpenWithNewTab(sender, e); break; case "OpenWithInternet": Process.Start("iexplore.exe", selfilename); break; case "OpenWithExplorer": Process.Start("explorer.exe", @"/select," + selfilename); break; case "SaveAs": OnSaveAsClick(sender, e); break; case "NewFile": OnNewFileClick(sender, e); break; //复制文件 case "CopyAFile": { if (File.Exists(selfilename)) { string dest = FileCore.NewName(selfilename); File.Copy(selfilename, dest); AddItem(dest); //selfilename = dest; OnCopyFile(sender, e); //MessageBox.Show(selfilename); } break; } case "DeleteFiles": { if (selfilename.IndexOf(recylebin) != -1) { DialogResult d = MessageBox.Show("彻底删除 " + listView1.SelectedItems.Count + " 个的文件 ", "删除文件", MessageBoxButtons.YesNo, MessageBoxIcon.Question); if (DialogResult.Yes == d) { foreach (ListViewItem listItem in listView1.SelectedItems) { string filename = path + "\\" + listItem.Text + fileExt; File.Delete(filename); string source_attachments = DirectoryCore.Get_AttachmentsDirectory(filename); if (Directory.Exists(source_attachments)) { Directory.Delete(source_attachments, true); } listItem.Remove(); } } } else { foreach (ListViewItem listItem in listView1.SelectedItems) { string source = path + "\\" + listItem.Text + fileExt; string dest = recylebin + "\\" + listItem.Text + fileExt; #region 移动文件 _attachments dest = FileCore.NewName(dest); string html = File.ReadAllText(source, Encoding.UTF8); string title = FileCore.GetHTMLTitleTag(html); if (title != "") { html = html.Replace(title, listItem.Text); } 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)) { Directory.Delete(dest_attachments); } if (Directory.Exists(source_attachments)) { Directory.Move(source_attachments, dest_attachments); } #endregion listItem.Remove(); } } listView1.Refresh(); OnDeleteFile(sender, e); break; } case "RenameFile": OnRenameFileClick(sender, e); break; case "Refresh": Refresh2(); break; // 复制选中的标题 case "CopyTitle": { string s = ""; for (int i = 0; i < listView1.SelectedItems.Count; i++) { s += listView1.SelectedItems[i].Text + "\r\n"; } Clipboard.SetDataObject(s, true); break; } //复制完整路径 case "CopyFileName": { string s = ""; for (int i = 0; i < listView1.SelectedItems.Count; i++) { //if (listView1.SelectedIndices != null) { s += listView1.Items[i].SubItems[1].Text + "\r\n"; } } Clipboard.SetDataObject(s, true); break; } } }
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 }