内容类型推而广之 [英] content type by extension

查看:100
本文介绍了内容类型推而广之的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有内置的函数,返回基于文件扩展名的内容类型?

Is there any built in function that returns the content type based on the file extension?

推荐答案

不,我知道的。但是你可以使用这个code:

Not that I know of. But you can use this code:

using Microsoft.Win32;

RegistryKey key = Registry.ClassesRoot.OpenSubKey(extension);
string contentType = key.GetValue("Content Type").ToString();

您将需要添加额外的code错误处理。

You'll need to add extra code for error handling.

注:扩展需要被$ P $一个点在 .TXT pfixed,像

Note: The extension needs to be prefixed by a dot, like in .txt.

这篇关于内容类型推而广之的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆