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.
Loading
VulpesPosted Oct 14, 2012, 11:09 AM
string partPath = "C:\\temp";
string strFullpath = partPath + "\\Docs\\";
string[] Files = (from path in Directory.GetFiles(strFullpath) let name = Path.GetFileName(path) where name.EndsWith(".pdf") || name.EndsWith(".docx") || name.EndsWith(".xlsx") || name.EndsWith(".xls") select path).ToArray();
If you just want the file name and not the full path then: select name rather than path
Sukesh MarlaPosted Oct 14, 2012, 11:47 AM
check this is correct answr if it helped