private NativeFilePickerAcceptType[] BuildFileTypesMap() { var allExtensions = FileTypeFilter.Except(new[] { "*" }); var acceptTypes = allExtensions .Select(fileType => BuildNativeFilePickerAcceptType(fileType)) .ToList(); if (!FileTypeFilter.Contains("*")) { var fullAcceptItem = new NativeFilePickerAcceptTypeItem { MimeType = "*/*", Extensions = allExtensions.ToArray() }; var fullAcceptType = new NativeFilePickerAcceptType() { Description = "All files", Accept = new[] { fullAcceptItem } }; acceptTypes.Insert(0, fullAcceptType); } return(acceptTypes.ToArray()); }
private NativeFilePickerAcceptType[] BuildFileTypesMap() { var acceptTypes = new List <NativeFilePickerAcceptType>(); foreach (var choice in FileTypeChoices) { var acceptType = new NativeFilePickerAcceptType(); acceptType.Description = choice.Key; var acceptItems = new List <NativeFilePickerAcceptTypeItem>(); foreach (var extension in choice.Value) { var acceptItem = new NativeFilePickerAcceptTypeItem() { MimeType = MimeTypeService.GetFromExtension(extension), Extensions = new[] { extension } }; acceptItems.Add(acceptItem); } acceptType.Accept = acceptItems.ToArray(); acceptTypes.Add(acceptType); } return(acceptTypes.ToArray()); }
private NativeFilePickerAcceptType BuildNativeFilePickerAcceptType(string fileType) { var acceptItem = new NativeFilePickerAcceptTypeItem { // This generic MIME type prevents unrelated // extensions from showing up in some browsers. MimeType = "*/*", Extensions = new[] { fileType } }; return(new NativeFilePickerAcceptType { // An empty string is consistent with UWP implementation. // However, some browsers show a generic description when // this string is empty. Description = string.Empty, Accept = new[] { acceptItem } }); }
private NativeFilePickerAcceptType[] BuildFileTypesMap() { var acceptTypes = new List <NativeFilePickerAcceptType>(); var mimeTypeGroups = FileTypeFilter .Except(new[] { "*" }) .GroupBy(f => MimeTypeService.GetFromExtension(f)) .ToArray(); var allAccepts = new List <NativeFilePickerAcceptTypeItem>(); foreach (var mimeTypeGroup in mimeTypeGroups) { var extensions = mimeTypeGroup.ToArray(); var acceptType = new NativeFilePickerAcceptType(); acceptType.Description = extensions.Length > 1 ? string.Empty : extensions.First(); var acceptItem = new NativeFilePickerAcceptTypeItem() { MimeType = mimeTypeGroup.Key, Extensions = extensions }; allAccepts.Add(acceptItem); acceptType.Accept = new[] { acceptItem }; acceptTypes.Add(acceptType); } if (allAccepts.Count > 1) { var fullAcceptType = new NativeFilePickerAcceptType() { Description = "All", Accept = allAccepts.ToArray() }; acceptTypes.Insert(0, fullAcceptType); } return(acceptTypes.ToArray()); }
private NativeFilePickerAcceptType[] BuildFileTypesMap() { var acceptTypes = new List <NativeFilePickerAcceptType>(); foreach (var choice in FileTypeChoices) { var acceptType = new NativeFilePickerAcceptType(); acceptType.Description = choice.Key; var acceptItem = new NativeFilePickerAcceptTypeItem() { MimeType = "*/*", Extensions = choice.Value.ToArray() }; acceptType.Accept = new NativeFilePickerAcceptTypeItem[] { acceptItem }; acceptTypes.Add(acceptType); } return(acceptTypes.ToArray()); }