Solved

OR clause fails (simple thing!)

Posted on 2013-02-03
2
156 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

AJAX ModalPopupExtender has a required property "TargetControlID" which may seem to be very confusing to new users. It means the server control that will be extended by the ModalPopup, for instance, if when you click a button, a ModalPopup displays,…
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This is used to tweak the memory usage for your computer, it is used for servers more so than workstations but just be careful editing registry settings as it may cause irreversible results. I hold no responsibility for anything you do to the regist…
As a trusted technology advisor to your customers you are likely getting the daily question of, ‘should I put this in the cloud?’ As customer demands for cloud services increases, companies will see a shift from traditional buying patterns to new…

863 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now