When uploading a file, you will usually want to check that the extension is of the correct type:

if ((String.Compare(fileExt, ".pdf", true)) == 0) {...}

However, the above code will not work if the letters are in a different case.

This is a better way which ignores the case:

if ((fileExt.IndexOf("pdf", StringComparison.OrdinalIgnoreCase) == 0)) {...}


An even better way (counteracts input such as "pdf2", etc.)

if (string.Equals(fileExt, ".pdf", StringComparison.OrdinalIgnoreCase)) {...}

Comments (2) -

bob United States
10/31/2012 12:20:10 AM #

Pretty cool!

ASP.Net Developer
ASP.Net Developer United States
2/17/2013 10:12:49 PM #

I'm new in the ASP.Net Field and I grew my career in this I always search new criteria about asp.net on internet. So this post is also helpful for me. Thank you for Sharing and must be share some new topics.

Pingbacks and trackbacks (1)+

Add comment

  Country flag
  • Comment
  • Preview