/// <summary> /// Gets the MIME type for the given file extension. /// The MIME type is 'application/octet-stream' if the given file extension is not associated with specific file formats. /// </summary> /// <param name="fileExtension"> The file extension.</param> /// <example> /// <code> /// string mimeType = MimeUtil.GetMimeType("png"); /// </code> /// </example> /// <since_tizen> 3 </since_tizen> public static string GetMimeType(string fileExtension) { string mime; int res = Interop.Mime.GetMime(fileExtension, out mime); if (res != (int)MimeError.None) { throw MimeExceptionFactory.CreateException((MimeError)res); } return(mime); }
/// <summary> /// Gets the file extensions for the given MIME type. /// </summary> /// <returns> /// If successful, returns the list of file extension strings for the given MIME type. /// The array of file extension is without the leading dot ('.'). /// </returns> /// <param name="mime"> The MIME type.</param> /// <example> /// <code> /// var extColl = MimeUtil.GetFileExtension("video/mpeg"); /// foreach ( string obj in extColl ) /// { /// Console.WriteLine(obj); /// } /// </code> /// </example> /// <since_tizen> 3 </since_tizen> public static IEnumerable <string> GetFileExtension(string mime) { IntPtr extensionArray = IntPtr.Zero; int length = -1; int res = Interop.Mime.GetFile(mime, out extensionArray, out length); if (res != (int)MimeError.None) { throw MimeExceptionFactory.CreateException((MimeError)res); } IntPtr[] extensionList = new IntPtr[length]; Marshal.Copy(extensionArray, extensionList, 0, length); Collection <string> coll = new Collection <string>(); foreach (IntPtr extension in extensionList) { coll.Add(Marshal.PtrToStringAnsi(extension)); Interop.Libc.Free(extension); } Interop.Libc.Free(extensionArray); return(coll); }