Solved

OR clause fails (simple thing!)

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
RLDC Reporting in Visual studio 11 30
Where is this file? 3 26
Phone Does Not Abide By CSS Breakpoint For Navigation Controls 6 22
ASP.NET MVC - Views 3 22
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…
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…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 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