Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Filtering by .docx in ios document picker

What is the Uniform Type Identifer to provide to a UIDocumentMenuViewController to allow a user to select *.docx files?

The documentation in System-Declared Uniform Type Identifiers does not list a public UTType that allows filtering by .docx. An identifier exists for a standard *.doc file but not *.docx, is there instead an alternate UTType?

This is my current code:

var allowedDocumentTypes = new string[] {
    UTType.RTF,
    UTType.Text,
    UTType.PDF,
    UTType.UTF8PlainText,
    UTType.RTFD,
    UTType.UTF16ExternalPlainText,
    UTType.UTF16PlainText,
    UTType.UTF8PlainText,
    UTType.FlatRTFD,
    "com.microsoft.word.doc",
    "com.microsoft.word.docx" // An attempt to include docx filtering.
};

var pickerMenu = new UIDocumentMenuViewController(allowedDocumentTypes, UIDocumentPickerMode.Open);
pickerMenu.DidPickDocumentPicker += (sender, args) =>
{
    args.DocumentPicker.DidPickDocument += (sndr, pArgs) =>
    {
        var securityEnabled = pArgs.Url.StartAccessingSecurityScopedResource();

        FileInfo fi = new FileInfo(pArgs.Url.Path);

        var result = new SelectFileResult();
        result.FilePath = fi.FullName;
        result.FileName = fi.Name;

        NSUrlRequest urlReq = NSUrlRequest.FromUrl(pArgs.Url);
        NSUrlResponse response;
        NSError error;;
        var data = NSUrlConnection.SendSynchronousRequest(urlReq, out response, out error);

        result.MimeType = response.MimeType;

        Action onFileConsumeDone = () =>
        {
            pArgs.Url.StopAccessingSecurityScopedResource();
        };

        onFileSelected(result, onFileConsumeDone);

    };

    // Display the document picker
    AppDelegate.TopViewController.PresentViewController(args.DocumentPicker, true, null);
};

pickerMenu.ModalPresentationStyle = UIModalPresentationStyle.Popover;
AppDelegate.TopViewController.PresentViewController(pickerMenu, true, null);

I had a shot in the dark and included the identifier com.microsoft.word.docx but it does not trigger filtering by docx.

My current solution is C# but objective-c and swift solutions accepted.

like image 571
matthewrdev Avatar asked Apr 11 '16 01:04

matthewrdev


1 Answers

Try org.openxmlformats.wordprocessingml.document

like image 159
Jason Avatar answered Oct 24 '22 05:10

Jason