private void 添加_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog1 = new OpenFileDialog(); openFileDialog1.Multiselect = true; if (openFileDialog1.ShowDialog() == DialogResult.OK) { ShellFileOperation fo = new ShellFileOperation(); String[] source = openFileDialog1.FileNames; String[] dest = new String[openFileDialog1.FileNames.Length]; for (int i = 0; i < openFileDialog1.FileNames.Length; i++) { dest[i] = FileCore.NewName(workpath + "\\" + Path.GetFileName(openFileDialog1.FileNames[i])); } fo.Operation = FileOperations.FO_COPY; fo.OwnerWindow = this.Handle; fo.SourceFiles = source; fo.DestFiles = dest; if (!fo.DoOperation()) { MessageBox.Show("添加文件过程中出错!", "附件", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(workpath); } }
private void 新建_Click(object sender, EventArgs e) { string s = FileCore.NewName(fileList1.path + "\\新建HTML文档.htm"); //MessageBox.Show(s); documentView1.NewDocument(s); fileList1.AddItem(s); }
private void htmEdit1_OnNewDocument(object sender, EventArgs e) { if (winTextBox1.Modified == false) { //新建立的文件名自动重命名 RichTextBox tmpRichTextBox1 = new RichTextBox(); tmpRichTextBox1.Text = htmEdit1.webBrowser1.Document.Body.InnerText; //移动空行 string s = ""; for (int i = 0; i < tmpRichTextBox1.Lines.Length; i++) { if (tmpRichTextBox1.Lines[i].Trim() != "\r\n") { s += tmpRichTextBox1.Lines[i] + "\r\n"; } } tmpRichTextBox1.Text = tmpRichTextBox1.Text.Trim(); WinTextBox tmpWinTextBox1 = new WinTextBox(); tmpWinTextBox1.Text = tmpRichTextBox1.Lines[0]; string filename = Path.GetDirectoryName(FullFileName) + "\\" + tmpWinTextBox1.Text + ".htm"; filename = FileCore.NewName(filename); if (!File.Exists(filename)) { string name1 = Path.GetFileNameWithoutExtension(filename); if (name1.Length <= winTextBox1.MaxLength) { winTextBox1.Text = name1; winTextBox1_LostFocus(sender, e); } } tmpRichTextBox1.Dispose(); tmpWinTextBox1.Dispose(); } }
protected override void WndProc(ref Message Msg) { if (Msg.Msg == 0x0233)// WM_DROPFILES { uint FilesCount = Win32API.DragQueryFile((int)Msg.WParam, 0xFFFFFFFF, null, 0); StringBuilder FileName = new StringBuilder(1024); ShellFileOperation fo = new ShellFileOperation(); String[] source = new String[FilesCount]; String[] dest = new String[FilesCount]; for (uint i = 0; i < FilesCount; i++) { Win32API.DragQueryFile((int)Msg.WParam, i, FileName, 1024); source[i] = FileName.ToString(); dest[i] = FileCore.NewName(workpath + "\\" + Path.GetFileName(FileName.ToString())); } Win32API.DragFinish((int)Msg.WParam); fo.Operation = FileOperations.FO_COPY; fo.OwnerWindow = this.Handle; fo.SourceFiles = source; fo.DestFiles = dest; if (!fo.DoOperation()) { MessageBox.Show("添加文件过程中出错!", "附件", MessageBoxButtons.OK, MessageBoxIcon.Error); } LoadData(workpath); return; } base.WndProc(ref Msg); }
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 确定_Click(object sender, EventArgs e) { if (!Directory.Exists(textBox1.Text)) { MessageBox.Show("目录不存在!", "导入", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } browser1.Enabled = false; textBox1.Enabled = false; textBox2.Enabled = false; Ok1.Enabled = false; comboBox1.Enabled = false; 刷新button.Enabled = false; errorCount = 0; successCount = 0; #region 0 所有支持文件类型(*.txt;*.rtf;*.html;*.htm) if (index == 0) { MessageBox.Show("目前不支持"); } #endregion #region 1 文本文档 转换成htm if (index == 1) { //CONVERT TXT TO HTML progressBar1.Maximum = listView1.Items.Count; progressBar1.Visible = true; for (int i = 0; i < listView1.Items.Count; i++) { Application.DoEvents(); string source = listView1.Items[i].SubItems[1].Text; string dest = textBox2.Text + "\\" + source.Remove(0, textBox1.Text.Length + 1); //remove dir dest = dest.Remove(dest.Length - 4, 4); //remove .txt dest += ".htm"; dest = FileCore.NewName(dest); string path = Path.GetDirectoryName(dest); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (i + 1 < listView1.Items.Count) { listView1.Items[i + 1].ImageIndex = 1; } listView1.EnsureVisible(i); if (ConvertTextFileToHtmlFile(source, dest) == true) { listView1.Items[i].ImageIndex = 2; } else { listView1.Items[i].ToolTipText = exceptionText; listView1.Items[i].ImageIndex = 3; } progressBar1.Value = i; } progressBar1.Visible = false; } #endregion #region 2 RTF 文档(*.rtf) 转换成htm if (index == 2) { MessageBox.Show("目前不支持"); } #endregion #region 3 网页文件(*.htm;*.html) 转换成单个文件 if (index == 3) { //CONVERT TXT TO HTML progressBar1.Maximum = listView1.Items.Count; progressBar1.Visible = true; for (int i = 0; i < listView1.Items.Count; i++) { Application.DoEvents(); string source = listView1.Items[i].SubItems[1].Text; string dest = textBox2.Text + "\\" + source.Remove(0, textBox1.Text.Length + 1);//remove dir dest = dest.ToLower(); if (dest.EndsWith(".html")) { dest = dest.Remove(dest.Length - 1, 1);//remove .html 的L } dest = FileCore.NewName(dest); string path = Path.GetDirectoryName(dest); if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (i + 1 < listView1.Items.Count) { listView1.Items[i + 1].ImageIndex = 1; } listView1.EnsureVisible(i); if (ConvertHtmToSingleFile(source, dest) == true) { listView1.Items[i].ImageIndex = 2; } else { listView1.Items[i].ToolTipText = exceptionText; listView1.Items[i].ImageIndex = 3; } progressBar1.Value = i; } progressBar1.Visible = false; } #endregion browser1.Enabled = true; textBox1.Enabled = true; textBox2.Enabled = true; Ok1.Enabled = true; comboBox1.Enabled = true; 刷新button.Enabled = true; MessageBox.Show(string.Format("导入数量:{0} 个\r\n成功导入:{1} 个\r\n失败导入:{2} 个", listView1.Items.Count, successCount, errorCount), "导入", MessageBoxButtons.OK, MessageBoxIcon.Information); }
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 }