Validate upload filetype


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.