?
Solved

OR clause fails (simple thing!)

Posted on 2013-02-03
2
Medium Priority
?
164 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Suggested Courses

752 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