In a C# 2010 desktop application, I want to change the application so that it will only allow users to select a
report that meets the following criteria:
1. part of the file name is "ErrorReport" and
2. The last node of the file name is .xlsx or .xls.
So far I have the following code:
string[] excelFiles = Directory.GetFiles(strDirectoryLoc, "*ErrorReport*")
.Select(path => Path.GetFileName(path))
.Where(x => (x.EndsWith(".xlsx") || x.EndsWith(".xls"))
&& (!x.StartsWith("~")))
.ToArray();
This code works when I am selecting only excel (*.xls or *.xlsx) files.
The problem occurs if the user selects a .pdf file iniitally and there is actually a file in the directory path
that meets the criteria I listed above. The code will ignore the .pdf file the user selects and will actually use the
excel file that is in the directory path.
Thus how can I change the code listed above to say the .pdf file is invalid?
Loading
Iftikar HussainPosted Jun 27, 2013, 2:49 AM
The above logic is fine. But not sure what exactly your are looking for. Can you provide more details? Are you trying to implement validation when user select file for uploading?
You can do like this
Regards,
Iftikar
Remember to click "Mark as Answer" on the post, if it helps you.