Search word or phrase within a file using LINQ
Posted by codingsense on September 16, 2008
Hi found a nice way to search a word or phrase within a file, so thought of sharing with you all.
string DirPath = Application.StartupPath + "\Search\"; string SearchText = "Temp"; string Files = (from file in new DirectoryInfo(DirPath).GetFiles() where new StreamReader(file.FullName).ReadToEnd().Contains(SearchText) select file.Name).ToArray<string>();
If you know a better way, please post a comment.
Happy Learning 🙂