1

Is it possible to get the name or information about a file extention in a UWP app?

Example: I'd like to call a method like:

string GetFileExtensionAppName(string extension)

And have an example like:

Pass in ".pdf" and get back "Adobe PDF Document"

or something similar. Is there an easy way to do this without creating a hard-coded dictionary? Just getting the name of the default application the extension is associated with works as well.

Nolan Blew
  • 374
  • 3
  • 18
  • See https://stackoverflow.com/questions/162331/finding-the-default-application-for-opening-a-particular-file-type-on-windows look at Ohad Schneider's answer. – Kevin Dec 21 '17 at 18:26
  • 1
    @Kevin cannot use `IQueryAssociations` in Universal windows app – Parsa Karami Dec 21 '17 at 18:38
  • 1
    @ParsaKarami that's not the answer I told the OP to look at. The one I pointed out PInvokes the Windows API. – Kevin Dec 21 '17 at 20:34

1 Answers1

1

For your example, StorageFile.DisplayType seems enough.

You can create a dummy file in your app temp folder with specific file extension to retrieve the DisplayType associated with the extension.

see https://learn.microsoft.com/en-us/uwp/api/windows.storage.storagefile.displaytype#Windows_Storage_StorageFile_DisplayType

  • This doesn't answer my question. I'm not looking for the name of the file itself. I'm looking for the name of the default app associated with it, or more the friendly-named MIME type as per my example. – Nolan Blew Apr 11 '18 at 18:19
  • My fault `DisplayType` – Opportunity Apr 12 '18 at 04:43