Freigeben über


file extension regular expression in c# in windows

Regular Expression : @"^(?:[\w]\:|\\)(\\[A-Z_\a-z_\-\s0-9\.]+)+\.(txt|gif|pdf|doc|docx|xls|xlsx|mht|pptx|ppt)$"

you can add any no of extensions to above regex expression.

How to use check is a filepath is matching with regular expression.

if(Regex.IsMatch(filePath, @"^(?:[\w]\:|\\)(\\[A-Z_\a-z_\-\s0-9\.]+)+\.(txt|gif|pdf|doc|docx|xls|xlsx|mht|pptx|ppt)$"))

{

// put your code here

}