难题求解:如何获得某个文件的类型(ContentType)?谢谢!!! 例如:

cwsj 2002-11-18 06:29:24
难题求解:如何获得某个文件的类型(ContentType)?谢谢!!! 例如:

Stream stream = File.OpenRead(fileName);

打开一个文件流我如何获得该文件的类型呢?



类似上传文件时获取文件类型的方法怎么用呢?
System.Web.HttpPostedFile files ;
files.ContentType;
...全文
120 3 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
saucer 2002-11-19
  • 打赏
  • 举报
回复
a lot of files do not have a content type, if they did, don't you think Microsoft would provide a ContentType property for FileInfo class? that said, here is something you might want to look into:

HOW TO: work with the Windows Registry to determine the content-type of a file based on the file extension
http://www.aspemporium.com/aspEmporium/cshrp/howtos/howto.asp?hid=19
sbf2000 2002-11-18
  • 打赏
  • 举报
回复
up
henryfan1 2002-11-18
  • 打赏
  • 举报
回复
在打开前用
System.IO.Path.GetExtension获得

111,116

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • AIGC Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧