How to compare a value returned by fileupload to ensure it contains 1 of 4 possible filename values (ASP.NET using C#) ?

I am developing an ASP.NET application using C# and .Net Framework 4.0.

I employ the following statement to retrieve the value returned from a browse by the user:

txtFilename.Text = FileUpload2.PostedFile.FileName;

How would you compare the value contained in txtFilename.Text to ensure that it contains one of the following 4 values keeping in mind that txtFilename.Text is prefaced by a drive:
1) MonthlyChecks.txt 2) ML1.txt 3) OS_Mastfile.txt 4) ReversePositive.txt
zimmer9Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

zephyr_hex (Megan)DeveloperCommented:
You can use Contains()

var values = new string[] {"MonthlyChecks.txt", "ML1.txt", "OS_Mastfile.txt", "ReversePositive.txt"};
var found = false;
foreach(var item in values) {
    if (txtFilename.Text.Contains(item)) {
    found = true;
    break;
  }
}
//evaluate found and do something

Open in new window


You could also use Path functions to get the filename from FileUpload2.PostedFile.FileName and do a direct comparison instead of contains()
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.