Solved

OR clause fails (simple thing!)

Posted on 2013-02-03
2
154 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 74

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

I recently went through the process of creating a Calendar Control of events with the basis of using a database to keep track of the dates that are selectable, one requirement was to have the selected date pop-up in a simple lightbox.  At first this…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

762 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

19 Experts available now in Live!

Get 1:1 Help Now