public static string GetContentTypeByExtName(string extName) { switch (extName.ToLower()) { case ".001": return "application/x-001"; case ".301": return "application/x-301"; case ".323": return "text/h323"; case ".906": return "application/x-906"; case ".907": return "drawing/907"; ......... .... return "application/x-wrk"; case ".ws": return "application/x-ws"; case ".ws2": return "application/x-ws"; case ".wsc": return "text/scriptlet"; case ".wsdl": return "text/xml"; case ".wvx": return "video/x-ms-wvx"; case ".xdp": return "application/vnd.adobe.xdp"; case ".xdr": return "text/xml"; case ".xfd": return "application/vnd.adobe.xfd"; case ".xfdf": return "application/vnd.adobe.xfdf"; case ".xhtml": return "text/html"; case ".xls": return "application/x-xls"; case ".xlw": return "application/x-xlw"; case ".xml": return "text/xml"; case ".xpl": return "audio/scpls"; case ".xq": return "text/xml"; case ".xql": return "text/xml"; case ".xquery": return "text/xml"; case ".xsd": return "text/xml"; case ".xsl": return "text/xml"; case ".xslt": return "text/xml"; case ".xwd": return "application/x-xwd"; case ".x_b": return "application/x-x_b"; case ".x_t": return "application/x-x_t"; } return "application/octet-stream"; }
http://www.dnbcw.com/biancheng/c/hqai113394.html
MS Word/Excel (xls.or.doc),文件头:D0CF11E0
{
switch (extName.ToLower())
{
case ".001":
return "application/x-001"; case ".301":
return "application/x-301"; case ".323":
return "text/h323"; case ".906":
return "application/x-906"; case ".907":
return "drawing/907";
......... ....
return "application/x-wrk"; case ".ws":
return "application/x-ws"; case ".ws2":
return "application/x-ws"; case ".wsc":
return "text/scriptlet"; case ".wsdl":
return "text/xml"; case ".wvx":
return "video/x-ms-wvx"; case ".xdp":
return "application/vnd.adobe.xdp"; case ".xdr":
return "text/xml"; case ".xfd":
return "application/vnd.adobe.xfd"; case ".xfdf":
return "application/vnd.adobe.xfdf"; case ".xhtml":
return "text/html"; case ".xls":
return "application/x-xls"; case ".xlw":
return "application/x-xlw"; case ".xml":
return "text/xml"; case ".xpl":
return "audio/scpls"; case ".xq":
return "text/xml"; case ".xql":
return "text/xml"; case ".xquery":
return "text/xml"; case ".xsd":
return "text/xml"; case ".xsl":
return "text/xml"; case ".xslt":
return "text/xml"; case ".xwd":
return "application/x-xwd"; case ".x_b":
return "application/x-x_b"; case ".x_t":
return "application/x-x_t";
}
return "application/octet-stream";
}
/// 是否是EXCEL文件
/// </summary>
/// <param name="filePath"></param>
/// <returns></returns>
private bool isExcelFile(string filePath)
{
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
byte[] b = new byte[4];
string temstr = "";
//将文件流读取的文件写入到字节数组
if (Convert.ToInt32(fs.Length) > 0)
{
fs.Read(b, 0, 4); fs.Close();
for (int i = 0; i < b.Length; i++)
{
temstr += Convert.ToString(b[i], 16);
}
}
if (temstr.ToUpper() == "D0CF11E0")
{ return true; }
else
{ return false; }
}