string FileContentType = _CanUploadFilePattern.ToLower();
FileContentType = FileContentType.Replace("*.gif", "image/gif");
FileContentType = FileContentType.Replace("*.jpg", "image/pjpeg");
FileContentType = FileContentType.Replace("*.bmp", "image/bmp");
FileContentType = FileContentType.Replace("*.avi", "video/avi|video/msvideo|video/x-msvideo");
FileContentType = FileContentType.Replace("*.afl", "video/animaflex");
FileContentType = FileContentType.Replace("*.asf", "video/x-ms-asf");
FileContentType = FileContentType.Replace("*.arj", "application/arj");
FileContentType = FileContentType.Replace("*.rar", "application/x-rar-compressed|application/octet-stream");
FileContentType = FileContentType.Replace("*.zip", "application/zip|multipart/x-zip|application/x-compressed|application/x-zip-compressed");
FileContentType = FileContentType.Replace("*.gz", "application/x-gzip-compressed|application/x-compressed");
FileContentType = FileContentType.Replace("*.wav", "audio/wav|audio/x-wav");
FileContentType = FileContentType.Replace("*.mpg", "audio/mpeg|video/mpeg");
FileContentType = FileContentType.Replace("*.mp3", "video/x-mpeg|audio/mpeg3|audio/x-mpeg-3|video/mpeg");
FileContentType = FileContentType.Replace("*.mpe", "video/mpeg");
FileContentType = FileContentType.Replace("*.pdf", "application/pdf");
FileContentType = FileContentType.Replace("*.rm", "audio/x-pn-realaudio|application/vnd.rn-realmedia");
FileContentType = FileContentType.Replace("*.rmi", "audio/mid");
FileContentType = FileContentType.Replace("*.swf", "application/x-shockwave-flash");
FileContentType = FileContentType.Replace("*.txt", "text/plain");以上代码是:_CanUploadFilePattern是在程序中定义的一个变量,用于设定允许上传文件的类型,然后再将文件类型转换为一串由MIME类型组成的字串,用于比较上传文件是否在设定类型中,这样就可以控制文件上传的类型了;上面代码中可以看到:*gif的MIME类型为:image/gif。,可以在VS中调试方式查看ContentType的值就OK。