Spire.Doc is a professional Word .NET library specifically designed for developers to create, read, write, convert and print Word document files. Get free and professional technical support for Spire.Doc for .NET, Java, Android, C++, Python.

Sat May 04, 2019 4:39 pm

How can I search a particular term in multiple files and generate a list with the names of the documents containing search term?

nerydias
 
Posts: 1
Joined: Sat May 04, 2019 4:30 pm

Mon May 06, 2019 9:56 am

Hi,

Thank you for your inquiry.
Please refer to the the following code to generate the list. If there is any question, please feel free to write back.
Code: Select all
            string dir = @"C:\Source";
            string[] docxs = Directory.GetFiles(dir, "*.docx");
            List<String> list = new List<String>();
            foreach (string fileName in docxs)
            {
                Document docx = new Document();
                docx.LoadFromFile(fileName);
                TextSelection[] text = docx.FindAllString("text", false, true);
                if (text != null)
                {
                        list.Add(fileName);
                }
            }

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Wed May 08, 2019 9:37 am

Hi,

Did my code help you? Could you please give us some feedback at your convenience? Thanks in advance.

Sincerely,
Nancy
E-iceblue support team
User avatar

nancy.yang
 
Posts: 184
Joined: Wed Apr 03, 2019 2:33 am

Return to Spire.Doc