[原创] 检查文件是否Flash格式(*.swf)
除了检查文件扩展名为*.swf, 最重要的是要检查文件头前8位是“FWF”及“CWS”。
public static bool ValidateFlash(string fileName)
{
byte[] header = new byte[8];
FileStream fs = new FileStream(fileName, FileMode.Open);
try
{
fs.Read(header, 0, 8);
}
finally
{
fs.Close();
}
string ext = Path.GetExtension(fileName);//文件扩展名
string sHeader = Encoding.Default.GetString(header);
sHeader = sHeader.Substring(0, 3);
//文件头三个字节"FWS(无压缩),CWS(标准ZLIB已压缩)"
return (ext.ToUpper() == ".SWF") && ((sHeader == "FWS") || (sHeader == "CWS"));
}