0
string[] sAllowedExt = new string[] { ".jpg", ".jpeg", ".gif", ".png",".pdf", ".docx", ".doc" }; (!sAllowedExt.Contains(file.FileName.Substring(file.FileName.IndexOf('.')).ToLower())) 

is not working . Please suggest something else.

1
  • 3
    Path.GetExtension(path) Commented Mar 31, 2016 at 7:04

1 Answer 1

5

i would use Path.GetExtension to determine if the extension of your file is valid.

string[] sAllowedExt = new string[] { ".jpg", ".jpeg", ".gif", ".png", ".pdf", ".docx", ".doc" }; string Extension = System.IO.Path.GetExtension(file.FileName); bool Result = sAllowedExt .Any(x => x.Equals(Extension, StringComparison.CurrentCultureIgnoreCase)); 
Sign up to request clarification or add additional context in comments.

Comments