문제

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