12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- 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<FileInfo> GetAllFiles(string dirPath, string FtpFileType)
- {
- List<FileInfo> rtn = new List<FileInfo>();
- 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<string> ReadTxt(string filePath)
- {
- List<string> rtn = new List<string>();
- 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;
- }
- }
- }
|