I want to search all XML files which contains a special tag, e.g. ‘field’ within their contents. How can I achieve this with Directory.GetFiles(...) method in C# ?
string[] filePathsFields = Directory.GetFiles(@"E:\Code\", "*.xml", SearchOption.AllDirectories);
Let we have
then
or
Pre .NET 4.0 solution:
Just replace
with
Select the resulting node itself:
returns nested
IEnumerable<>because each document can contain several resulting nodes.To select only file names:
or if you don’t want to load data to appropriate XDocument object:
but the last will return a lot of additional stuff and junk, I guess.
File and folder exclusion:
Attributes count condition: