Posted By

housecor on 11/12/10


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

franksmile0310
tonicglop


Validate upload filetype


 / Published in: C#
 

  1. /// <summary>
  2. /// Returns true if the filetype uploaded has an accepted extension.
  3. /// </summary>
  4. /// <param name="filename"></param>
  5. /// <returns></returns>
  6. private bool ValidFileType(string filename)
  7. {
  8. if (filename.Length == 0) return true;
  9. string uploadedFileExtension = Path.GetExtension(filename).Substring(1);
  10.  
  11.  
  12.  
  13. foreach (string extension in ValidFileExtensions)
  14. {
  15. if (uploadedFileExtension == extension) return true;
  16. }
  17. return false;
  18. }

Report this snippet  

You need to login to post a comment.