TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Sie Ste
NA
196
184.5k
C# logic use only file selected by user
Jun 26 2013 4:52 PM
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?
Reply
Answers (
1
)
C# obtain db connections from app.config of called program
How to Export gridview which contain images column to excel