Вопрос

I'm making a Windows Universal App in c#. I get a MIME type from my server and I have to save a file with the extension that that MIME type represents. How can I convert this MIME type to a file extension in a way that works with Windows Universal Apps, so with both Windows Phone 8.1 and Windows 8.1?

I don't mind a:

#if Windows_Phone
{code}
#elif
{code}
#endif

Construction.

Это было полезно?

Решение

You don't have access to the Registry or any similar Windows magic, neither in W8 nor in WP8. There's only one exception I know of: Windows.Graphics.Imaging.BitmapDecoder.GetDecoderInformationEnumerator() tells you both about mimetypes and extensions, but only of image formats installed on the local machine.

You'll probably need to manually create a dictionary which maps from mimetype to extension. Be warned: this is a neverending task. E.g. the mimetype "audio/x-mpegurl" has two extensions: .m3u and .m3u8. At the same time many servers claim that .m3u files have the mimetype "audio/m3u". So you'll end up tweaking and updating this dictionary over and over ...

Другие советы

I'm afraid there is no platform API available for this. You will need to create your own mapping.

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top