Reputation: 69
How can I search multiple PDF files in directory for a specific 'Author' name and get a path to that file if found? Currently I'm browsing through directory using EnumerateFiles
and then I'm looping through to display all the Author names from each PDF file with PDfReader
. I just don`t know how to search now for that specific Author name.
My code below:
path = @"C:\Users\thomas\Desktop\PDFfiles";
var files = Directory.EnumerateFiles(path, "*.pdf", SearchOption.AllDirectories);
foreach (string currentFile in files)
{
PdfReader reader = new PdfReader(currentFile);
string authorName = reader.Info["Author"];
listBox1.Items.Add("Author is: " + authorName);
}
I'm getting a list of Authors names in my ListBox
, but how I can search for a specific name within all PDF files?
Thank you
Upvotes: 1
Views: 634
Reputation: 598
You may need to use new list to save results with your selected author such as: newList = listBox1.Items.Where(x => x.Text == authorName);
Upvotes: 3