?
Solved

OR clause fails (simple thing!)

Posted on 2013-02-03
2
Medium Priority
?
166 Views
Last Modified: 2013-02-03
This is work...if file extension is not pdf, doc, docx or txt, i want to display a msg.
The file extension IS a pdf but still fails....but it's an OR...it should work...


 if (file.GetExtension() != ".pdf" || file.GetExtension() != ".doc" || file.GetExtension() != ".docx" || file.GetExtension() != ".txt")
                {
                    lmsg.Text = "Valid files are: pdf, doc, docx and text";
                    return;
                }

Open in new window

0
Comment
Question by:Camillia
2 Comments
 
LVL 75

Expert Comment

by:käµfm³d 👽
ID: 38849541
What does GetExtension return in each case? Is it, for example, ".pdf" or "pdf" returned? It will make a difference based on how you currently have your code set up. Also note that case is important when performing string comparisons in the manner you are currently doing.
0
 
LVL 29

Accepted Solution

by:
Paul Jackson earned 2000 total points
ID: 38849610
Change to && where you have ||

 if (file.GetExtension() != ".pdf" && file.GetExtension() != ".doc" && file.GetExtension() != ".docx" && file.GetExtension() != ".txt")
                {
                    lmsg.Text = "Valid files are: pdf, doc, docx and text";
                    return;
                }
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
this video summaries big data hadoop online training demo (http://onlineitguru.com/big-data-hadoop-online-training-placement.html) , and covers basics in big data hadoop .
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month17 days, 10 hours left to enroll

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question