Answered by:
file open picker contract: any way to get the required extension files?

Question
-
Hello guys.
quick question: is there any way for an app that implements the file open picker contract to get the list of file extensions that can be opened? I've noticed that the FileOpenPickerUI object has a method which can be used to see if a file can be added to the basket (canAddFile), but i haven't found a way to get the list of allowed extensions...
oh, and since we're at it, how about improving the automatically generated code so that the selectionmode property of the listview is initialized from the FileOpenPickerUI's selectionMode property that is passed to the activation function?
thanks.
Luis Abreu
Monday, March 26, 2012 2:19 PM
Answers
-
When your app is activated for FileOpenPicker contract, you can inspect the activation event args to determine what the requested file types were by the caller. Then you can filter your UI accordingly...
function activated (eventArgs) { if (eventArgs.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.fileOpenPicker) { var fileOpenPickerUI = eventArgs.detail.fileOpenPickerUI; var requestedFileTypes = fileOpenPickerUI.allowedFileTypes; } }
See http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.pickers.provider.fileopenpickerui.aspx for more information.
Justin Cooperman
- Proposed as answer by Justin Cooperman Tuesday, March 27, 2012 12:13 AM
- Edited by Justin Cooperman Tuesday, March 27, 2012 12:14 AM
- Marked as answer by Luis Miguel Abreu Tuesday, March 27, 2012 8:23 AM
Tuesday, March 27, 2012 12:13 AM
All replies
-
I am not sure I understand what you are asking. You can specify the file formats in the datapackage:
http://msdn.microsoft.com/en-us/library/windows/apps/hh770848.aspx
-Jeff
Jeff Sanders (MSFT)
- Proposed as answer by Jeff SandersMicrosoft employee, Moderator Monday, March 26, 2012 5:55 PM
Monday, March 26, 2012 5:55 PMModerator -
Suppose I'm doing an app which can get any file from a remote web service. Now, after registering my app, it can be used by any other app which uses a file open picker, right?
Lets assume that we've got another app which is only interested in txt files. is there any way for me to get that info from the FileOpenPickerUI object that I receive in the app that implements the file open picker contract so that I'll only show txt files in that case? With my current code, I'm showing the client app all the files I have and that makes no sense if the client app is only interested in getting txt files.
Regarding the second question, what I'm suggesting is improving the file open picker generated code so that it addapts the selection mode property of the list view control to the way the dialog is opened (ie, if I'm calling pickSingleFileAsync, set it to single; otherwise, set it to multiple).
Luis Abreu
Monday, March 26, 2012 8:49 PM -
When your app is activated for FileOpenPicker contract, you can inspect the activation event args to determine what the requested file types were by the caller. Then you can filter your UI accordingly...
function activated (eventArgs) { if (eventArgs.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.fileOpenPicker) { var fileOpenPickerUI = eventArgs.detail.fileOpenPickerUI; var requestedFileTypes = fileOpenPickerUI.allowedFileTypes; } }
See http://msdn.microsoft.com/en-us/library/windows/apps/windows.storage.pickers.provider.fileopenpickerui.aspx for more information.
Justin Cooperman
- Proposed as answer by Justin Cooperman Tuesday, March 27, 2012 12:13 AM
- Edited by Justin Cooperman Tuesday, March 27, 2012 12:14 AM
- Marked as answer by Luis Miguel Abreu Tuesday, March 27, 2012 8:23 AM
Tuesday, March 27, 2012 12:13 AM -
Hello Justin.
That's it!
thanks.
Luis Abreu
Tuesday, March 27, 2012 8:23 AM -
It's also important to note that your app will only show up in the list of apps to pick from if you support at least one of the file types the caller is requesting. You declare which file types you support for the FileOpenPicker in the app manifest.
Justin Cooperman
Tuesday, March 27, 2012 8:46 PM