private void GetDocFile(DirectoryInfo userPath, string userName) { WTPMsg wTPMsg; foreach (var v in userPath.GetFiles()) { string[] ext = v.Name.Split('.'); if (ext[ext.Length - 1].ToUpper() != "DOC" && ext[ext.Length - 1].ToUpper() != "DOCX") { continue; } if ((v.Attributes & FileAttributes.Hidden) > 0) { continue; } if (v.Name.IndexOf("~$") == 0) { continue; } wTPMsg = new WTPMsg() { FileName = v.Name, FullFileName = v.FullName, UserName = userName, pority = false }; WordToPdf.AddMsg(wTPMsg); } foreach (var v in userPath.GetDirectories()) { GetDocFile(v, userName); } }
public static bool DoWTPMsg(WTPMsg wTPMsg) { if (!File.Exists(wTPMsg.FullFileName)) { WTPFileMsgList.Remove(wTPMsg); return(false); } if (WordToPDF(wTPMsg.FullFileName) == "") { return(false); } WTPFileMsgList.Remove(wTPMsg); return(true); }
public static void AddMsg(WTPMsg wTPMsg) { if (!File.Exists(wTPMsg.FullFileName)) { return; } if (wTPMsg.FileName.IndexOf("~$") == 0) { return; } if (WTPFileMsgList.FindIndex(t => t.FullFileName == wTPMsg.FullFileName && t.UserName == wTPMsg.UserName) == -1) { WTPFileMsgList.Add(wTPMsg); } }
private void AddNoConvertDocFile(DirectoryInfo userPath, string userName) { WTPMsg wTPMsg; foreach (var v in userPath.GetFiles()) { if (UserHelper.isRefresh) { return; } string[] ext = v.Name.Split('.'); if (ext[ext.Length - 1].ToUpper() != "DOC" && ext[ext.Length - 1].ToUpper() != "DOCX") { continue; } if ((v.Attributes & FileAttributes.Hidden) > 0) { continue; } if (v.Name.IndexOf("~$") == 0) { continue; } string newFileName = WordToPdf.GetPdfPath(v.FullName); if (File.Exists(newFileName)) { continue; } wTPMsg = new WTPMsg() { FileName = v.Name, FullFileName = v.FullName, UserName = userName, pority = false }; WordToPdf.AddMsg(wTPMsg); } foreach (var v in userPath.GetDirectories()) { AddNoConvertDocFile(v, userName); } }
private void fileWatcher_Created(object sender, FileSystemEventArgs e) { if (!e.FullPath.Replace(fileWatcher.Path, "").Contains('\\')) { return; } string [] ext = e.Name.Split('.'); if (ext[ext.Length - 1].ToUpper() != "DOC" && ext[ext.Length - 1].ToUpper() != "DOCX") { return; } string[] tmpStr = e.Name.Split('\\'); WTPMsg wTPMsg = new WTPMsg() { FileName = tmpStr[tmpStr.Length - 1], FullFileName = e.FullPath, UserName = tmpStr[0], pority = false }; WordToPdf.AddMsg(wTPMsg); }
public static List <FileMsg> GetAllFile(DirectoryInfo root, string userName, string userID, string newPath, string oldPath) { List <FileMsg> tmpList = new List <FileMsg>(); FileInfo[] files = root.GetFiles(); DirectoryInfo[] info = root.GetDirectories(); foreach (var v in files) { if ((v.Attributes & FileAttributes.Hidden) == FileAttributes.Hidden) { continue; } if (v.Extension.ToUpper() == "") { continue; } if (v.Extension.ToUpper() == ".RAR") { continue; } if (v.Extension.ToUpper() == ".ZIP") { continue; } double filesize = System.Math.Ceiling(v.Length / 1024.0); //string strSize = ""; //if (filesize > 1024) // strSize = Math.Round((filesize / 1024.0), 2).ToString() + "M"; //else // strSize = filesize.ToString() + "K"; if (v.Extension.ToUpper() == ".PDF") { if (v.Name.IndexOf("W2P_tmp~W2P_tmp~") == 0) { continue; } string tmpPageCount = FileHelper.GetPDFofPageCount(v.FullName).ToString(); if (tmpPageCount == "-1") { tmpList.Add(new FileMsg() { FileSize = filesize, UserID = userID, FullName = newPath + "\\" + v.FullName.Replace(oldPath, "").Trim('\\'), FileName = v.Name, PageCount = "----", Count = "1", PrintColor = "黑白", VerForm = "正反", LoadTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), state = "0", isNew = true, isInit = true, isNormalFile = true }); } else { tmpList.Add(new FileMsg() { FileSize = filesize, UserID = userID, FullName = newPath + "\\" + v.FullName.Replace(oldPath, "").Trim('\\'), FileName = v.Name, PageCount = tmpPageCount, Count = "1", PrintColor = "黑白", VerForm = (tmpPageCount == "1" ? "单面" : "正反"), LoadTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), state = "0", isNew = true, isInit = true }); } } else if (v.Extension.ToUpper() == ".DOC" || v.Extension.ToUpper() == ".DOCX") { string newFileName1 = WordToPdf.GetPdfName(v.FullName); string newFileName = WordToPdf.GetPdfPath(v.FullName); if (File.Exists(newFileName)) { string tmpPageCount = FileHelper.GetPDFofPageCount(newFileName).ToString(); tmpList.Add(new FileMsg() { FileSize = filesize, UserID = userID, FullName = newPath + "\\" + newFileName.Replace(oldPath, "").Trim('\\'), FileName = v.Name, PageCount = tmpPageCount, Count = "1", PrintColor = "黑白", VerForm = tmpPageCount == "1"?"单面": "正反", LoadTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), state = "0", isNew = true, isInit = true }); } else { WTPMsg wTPMsg = new WTPMsg(); string[] tmpStr = v.FullName.Split('\\'); wTPMsg.FileName = tmpStr[tmpStr.Count() - 1]; wTPMsg.FullFileName = v.FullName; wTPMsg.UserName = userName; LogOperate.Add("刷新检测Word没有转化,当前路径:" + newFileName + "," + userName); WordToPdf.AddMsg(wTPMsg); return(null); } } else { tmpList.Add(new FileMsg() { FileSize = filesize, UserID = userID, FullName = newPath + "\\" + v.FullName.Replace(oldPath, "").Trim('\\'), FileName = v.Name, PageCount = "----", Count = "1", PrintColor = "黑白", VerForm = "正反", LoadTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"), state = "0", isNew = true, isInit = true, isNormalFile = true }); } } foreach (DirectoryInfo dir in info) { tmpList.AddRange(GetAllFile(dir, userName, userID, newPath, oldPath)); } return(tmpList); }