获取文件路径 string fileExtension = System.IO.Path.GetExtension(filePath).ToLower(); bool flag = true; string[] AllowExtension = { ".doc", ".xls", ".ppt", ".docx", ".xlsx", ".pptx", ".txt", ".rar", ".zip", ".jpg", ".jpeg", ".bmp", ".flv", ".rtf" }; for (int i = 0; i < AllowExtension.Length; i++) { if (fileExtension == AllowExtension[i]) { flag = false; } } if (flag) { MessageBox.Show("此文件类型不允许上传,请压缩后再上传"); return; } 上传操作