コード例 #1
0
        public static FileStream OpenFile(string fileName, string extention)
        {
            string filePath = @"E:\Documents\GitHub\ColleCument\files";

            //שליפה מהדטה בייס כדי לפרק את התאריך כדי לדעת את מיקום הקובץ
            CollecumentData.File file = GetFileById(fileName);

            filePath += "\\" + file.Date_Creation.Year.ToString();
            filePath += "\\" + file.Date_Creation.Month.ToString();
            filePath += "\\" + file.Date_Creation.Day.ToString();
            fileName += '.' + GetExtentionById(extention);
            filePath += "\\" + fileName;
            FileStream files = System.IO.File.Open(filePath, FileMode.Open);

            return(files);
        }
コード例 #2
0
        public static List <CollecumentData.File> SearchTextInFile(string keyword)
        {
            //FileStream inFile = new FileStream(@"E:\Documents\Hello.docx", FileMode.Open, FileAccess.Read);

            string directory                        = @"E:\Documents\GitHub\ColleCument\files";
            string searchString                     = keyword;
            bool   searchSubdirectories             = true;
            bool   caseSensitive                    = true;
            bool   useRegex                         = false;
            List <CollecumentData.File> searchfiles = new List <CollecumentData.File>();
            string docxText                         = null;
            var    isMatch = useRegex ? new Predicate <string>(x => Regex.IsMatch(x, searchString, caseSensitive ? RegexOptions.None : RegexOptions.IgnoreCase))
                    : new Predicate <string>(x => x.IndexOf(searchString, caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase) >= 0);

            foreach (var filePath in Directory.GetFiles(directory, "*.docx", searchSubdirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly))
            {
                using (var stream = System.IO.File.Open(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
                {
                    if (stream.Length == 0)
                    {
                        continue;
                    }
                    docxText = new DocxToStringConverter(stream).Convert();

                    {
                        if (isMatch(docxText))
                        {
                            using (DBCollecumentEntities context = new DBCollecumentEntities())
                            {
                                string idFile             = stream.Name.Substring(stream.Name.Length - 41).ToString();
                                string id                 = idFile.Remove(idFile.Length - 5);
                                CollecumentData.File file = context.Files.FirstOrDefault(x => x.ID == id);
                                searchfiles.Add(file);
                            }
                        }
                    }
                }
            }
            return(searchfiles);
        }
コード例 #3
0
 public static void SaveNewFileInDB(string fileid, string selectCategory, string description, string CreatorName, string Extension, string Remark)
 {
     using (DBCollecumentEntities context = new DBCollecumentEntities())
     {
         CollecumentData.File file = new CollecumentData.File();
         file.ID            = fileid;
         file.Description   = description;
         file.CreatorID     = Logic.GetUserByName(CreatorName);
         file.Date_Creation = DateTime.Now;
         file.ExtensionID   = GetExtentionByName(Extension);
         file.Version       = 1;
         file.CategoryID    = GetCategoryById(selectCategory);
         file.Remark        = Remark;
         context.Files.Add(file);
         try
         {
             context.SaveChanges();
         }
         catch (Exception)
         {
             throw;
         }
     };
 }