dc

dc

  • NA
  • 663
  • 0

C# locate files with various extensions

Oct 14 2012 11:00 AM
In a C# 2008 application, I have the code listed below to select pdf files from a specific location.
string partPath = "C:\\temp";
string strFullpath =  partPath + "\\Docs\\";
                    string[] Files = Directory.GetFiles(strFullpath, "*pdf")
                                                                 .Select(path => Path.GetFileName(path))
                                                                 .ToArray();
I need to be able to look for other document types like *.docx, *.xlsx, and *.xls.

Thus can you tell me how to modify the code listed above and/or write new code where I
can pick records where the last node is either *.pdf, *.xls, *xlsx, or *.docx.

Answers (2)