using System; using System.Collections.Generic; using System.Text; using System.Configuration; using System.IO; using System.Text.RegularExpressions; using DSOFile; namespace EMISOnline.WinService.Common { public class FileHelper { static object locker = new object();//创建锁 public static string GetFilePropertiesComments(string filePath) { lock (locker) { DSOFile.OleDocumentPropertiesClass file = new OleDocumentPropertiesClass(); file.Open(filePath, true, dsoFileOpenOptions.dsoOptionDefault); string Comments = file.SummaryProperties.Comments; file.Close(false); return Comments; } } public static void SaveFilePropertiesComments(string filePath, string Comments) { lock (locker) { DSOFile.OleDocumentPropertiesClass file = new OleDocumentPropertiesClass(); file.Open(filePath, false, dsoFileOpenOptions.dsoOptionDefault); file.SummaryProperties.Comments = Comments; file.Save(); file.Close(false); } } public static List GetAllFiles(string dirPath, string FtpFileType) { List rtn = new List(); DirectoryInfo folder = new DirectoryInfo(dirPath); //先查找本目录下的文件信息 string[] arysFilter = FtpFileType.Split('|'); foreach (string filter in arysFilter) { foreach (FileInfo info in folder.GetFiles(filter)) { rtn.Add(info); } } //递归查找子目录文件 foreach (DirectoryInfo d in folder.GetDirectories()) { rtn.AddRange(GetAllFiles(d.FullName,FtpFileType)); } return rtn; } public static List ReadTxt(string filePath) { List rtn = new List(); StreamReader sr = new StreamReader(filePath, Encoding.Default); String line; while ((line = sr.ReadLine()) != null) { string str = line.ToString(); rtn.Add(str); } sr.Close(); sr.Dispose(); return rtn; } } }