How do I get File Type Information based on extension? (not MIME) in c#

后端 未结 5 1953
失恋的感觉
失恋的感觉 2020-12-01 12:23

How do I get the general File type description based on extension like Explorer does it? So not MIME but the information that the end-user sees, like.

.doc = Microso

5条回答
  •  情书的邮戳
    2020-12-01 13:06

    Some extra if's for unknown file types in XP.. May not really give the right results when using it with anything but FriendlyDocName, but just as an example:

    public static string FileExtentionInfo(AssocStr assocStr, string doctype)
    {
       if ((doctype.Length <= 1) || !doctype.StartsWith(".")) return "";
    
       uint pcchOut = 0;
       AssocQueryString(AssocF.Verify, assocStr, doctype, null, null, ref pcchOut);
    
       if (pcchOut == 0) return (doctype.Trim('.').ToUpper() + " File");
    
       StringBuilder pszOut = new StringBuilder((int)pcchOut);
       AssocQueryString(AssocF.Verify, assocStr, doctype, null, pszOut, ref pcchOut);
       return pszOut.ToString();
    }
    

提交回复
热议问题