相关疑难解决方法(0)

Windows注册表中的Mime类型

在我使用C#构建的Windows服务中,我尝试根据文件扩展名设置mime类型,如下所示

static string GetMimeType(string fileName)
        {
            string mimeType = "application/unknown";
            string ext = Path.GetExtension(fileName).ToLower();

            Microsoft.Win32.RegistryKey regKey = Microsoft.Win32.Registry.ClassesRoot.OpenSubKey(ext);

            if (regKey != null && regKey.GetValue("Content Type") != null)
                mimeType = regKey.GetValue("Content Type").ToString();

            return mimeType;
        } 
Run Code Online (Sandbox Code Playgroud)

在生产服务器上,由于显而易见的原因,我们没有安装Acrobat或word.我该如何解决这个问题?还有其他设置mime类型的方法吗?如果不是如何在生产服务器上创建这些mime类型而不必安装这些软件.

提前致谢

c# windows mime-types

4
推荐指数
1
解决办法
1万
查看次数

标签 统计

c# ×1

mime-types ×1

windows ×1