Ejemplo n.º 1
0
        private async void BtnSelectFileOnClick()
        {
            var customFileType = new FilePickerFileType(new Dictionary <DevicePlatform, IEnumerable <string> >
            {
                { DevicePlatform.Android, new[] { "application/vnd.openxmlformats-officedocument.wordprocessingml.document" } }
            });

            var pickResult = await FilePicker.PickAsync(new PickOptions
            {
                FileTypes   = customFileType,
                PickerTitle = "Выбранный файл"
            });

            if (pickResult != null)
            {
                TextView fileTextView = FindViewById <TextView>(Resource.Id.selectFile);
                fileTextView.Text = pickResult.FileName;
                try
                {
                    using (WordprocessingDocument filestream = WordprocessingDocument.Open(await pickResult.OpenReadAsync(), false))
                    {
                        fileTextView.Hint = filestream.MainDocumentPart.Document.Body.InnerText;
                    }
                }
                catch (Exception)
                {
                    fileTextView.Hint = "Ошибка";
                }
            }
        }
Ejemplo n.º 2
0
 static List <FileDialogFilter>?Convert(FilePickerFileType fileTypes)
 {
     if (fileTypes is IFilePickerFileTypeWithName @interface)
     {
         var values = @interface.GetFileTypes();
         if (values.Any())
         {
             return(values.Select(x => new FileDialogFilter
             {
                 Name = x.Item1,
                 Extensions = FormatExtensions(x.Item2, trimLeadingPeriod: true).ToList(),
             }).ToList());
         }
     }
     else
     {
         var extensions = fileTypes.Value;
         if (extensions.Any())
         {
             return(new()
             {
                 new FileDialogFilter
                 {
                     Extensions = FormatExtensions(extensions, trimLeadingPeriod: true).ToList(),
                 },
             });
         }
     }
     return(null);
 }
Ejemplo n.º 3
0
        private async void BtnAddMafile_Clicked(object sender, EventArgs e)
        {
            var customFileType = new FilePickerFileType(new Dictionary <DevicePlatform, IEnumerable <string> >
            {
                { DevicePlatform.Android, new[] { "application/maFile" } },
            });


            var pickResult = await FilePicker.PickMultipleAsync(new PickOptions
            {
            });

            if (pickResult != null)
            {
                foreach (var mafile in pickResult)
                {
                    try
                    {
                        File.Copy(mafile.FullPath, Path.Combine($"{DependencyService.Get<IFileService>().GetRootPath()}/maFiles", mafile.FileName));
                    }catch (Exception ex)
                    {
                        if (ex.Message.Contains("File already exists."))
                        {
                            continue;
                        }
                        else
                        {
                            await DisplayAlert("Error", "Something went wrong :(", "Ok");
                        }
                    }
                }
            }
            CreateMafileListView();
        }
Ejemplo n.º 4
0
        private async Task CustomFileTypes(params string[] args)
        {
            try
            {
                var customFileType =
                    new FilePickerFileType(new Dictionary <DevicePlatform, IEnumerable <string> >
                {
                    { DevicePlatform.iOS, args }, // or general UTType values
                    { DevicePlatform.Android, args },
                    { DevicePlatform.UWP, args }
                });

                var options = new PickOptions
                {
                    PickerTitle = "Please select a file file",
                    FileTypes   = customFileType,
                };

                var result = await FilePicker.PickAsync(options);

                if (result != null)
                {
                    lFileName.Text = result.FileName;
                    lFilePath.Text = result.FullPath;
                }
            }
            catch (Exception ex)
            {
                lFileName.Text = ex.ToString();
                lFilePath.Text = string.Empty;
            }
        }
Ejemplo n.º 5
0
        private async void chooseImage(object sender, RoutedEventArgs e)
        {
            var customFileType =
                new FilePickerFileType(new Dictionary <DevicePlatform, IEnumerable <string> >
            {
                { DevicePlatform.Android, new string[] { "image/png", "image/jpeg" } },
                { DevicePlatform.UWP, new string[] { ".jpg", ".png" } }
            });
            var options = new PickOptions
            {
                PickerTitle = "Pilih Gambar..",
                FileTypes   = customFileType,
            };
            var result = await FilePicker.PickAsync(options);

            byte[] hasil;
            if (result != null)
            {
                Stream stream = await result.OpenReadAsync();

                using (var streamReader = new MemoryStream())
                {
                    stream.CopyTo(streamReader);
                    hasil = streamReader.ToArray();
                }
                string fileName = result.FileName;
                imageLaporan             = new UploadedImage(fileName, hasil, 0);
                txtNamaFile.Text         = fileName;
                gridFile.Visibility      = Visibility.Visible;
                txtStatusFile.Visibility = Visibility.Collapsed;
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Open a .sketch360 file
        /// </summary>
        /// <param name="parameter">the parameter is not used.</param>
        /// <returns>an async task</returns>
        protected override async Task ExecuteAsync(object parameter)
        {
            var customFileType =
                new FilePickerFileType(new Dictionary <DevicePlatform, IEnumerable <string> >
            {
                { DevicePlatform.Android, new[] { "application/octet-stream" } },
                { DevicePlatform.UWP, new[] { "application/octet-stream" } },
            });

            var options = new PickOptions
            {
                PickerTitle = "Please select a Sketch 360 File",
                FileTypes   = customFileType,
            };

            var fileData = await Xamarin.Essentials.FilePicker.PickAsync(options).ConfigureAwait(true);

            if (fileData == null)
            {
                return;
            }
            using var stream = await fileData.OpenReadStreamAsync().ConfigureAwait(true);

            using var zipFile = new ZipFile(stream);
            var entry = zipFile.GetEntry("sketch360.json");

            using var jsonStream = zipFile.GetInputStream(entry);
            using var reader     = new StreamReader(jsonStream);
            var json = await reader.ReadToEndAsync().ConfigureAwait(true);

            (App.Current as App).LoadSketch(json);
        }
Ejemplo n.º 7
0
        public ManagedFileChooserFilterViewModel(FilePickerFileType filter)
        {
            Name = filter.Name;

            if (filter.Patterns?.Contains("*.*") == true)
            {
                return;
            }

            _patterns = filter.Patterns?
                        .Select(e => new Regex(Regex.Escape(e).Replace(@"\*", ".*").Replace(@"\?", "."), RegexOptions.Singleline | RegexOptions.IgnoreCase))
                        .ToArray();
        }
Ejemplo n.º 8
0
        async void PickPDF(System.Object sender, System.EventArgs e)
        {
            var customFileType = new FilePickerFileType(new Dictionary <DevicePlatform, IEnumerable <string> >
            {
                { DevicePlatform.Android, new[] { "application/pdf" } },
            });
            var archive = await FilePicker.PickAsync(new PickOptions
            {
                FileTypes   = customFileType,
                PickerTitle = "Selecione o arquivo PDF com seus horários"
            });

            await Navigation.PushAsync(new PageSync());
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Gets the CurrentDataFolder folder
        /// </summary>
        /// <returns>
        /// True if a file was picked. False if not.
        /// </returns>
        public static async Task <bool> PickCurrentInputFile()
        {
            try
            {
                FilePickerFileType customFileType =
                    new FilePickerFileType(
                        new Dictionary <DevicePlatform,
                                        IEnumerable <string> >
                {
                    //{ DevicePlatform.iOS, new[] { "public.my.comic.extension" } }, // TODO add these or general UTType values
                    { DevicePlatform.Android, new[] { "application/octet-stream" } },
                    { DevicePlatform.UWP, new[] { ".gpkg", ".gramps" } },
                    //{ DevicePlatform.macOS, new[] { "cbr" } }, // TODO add these or general UTType values
                }
                        );

                var options = new PickOptions
                {
                    PickerTitle = "Please select a Gramps input file",
                    FileTypes   = customFileType,
                };

                FileResult result = await FilePicker.PickAsync(options);

                if (result == null)
                {
                    return(false); // user canceled file picking
                }

                Debug.WriteLine("Picked file name is: " + result.FileName);

                DataStore.Instance.AD.CurrentInputStream = await result.OpenReadAsync();

                DataStore.Instance.AD.CurrentInputStreamPath = result.FullPath;
            }

            // TODO fix this. Fail and force reload next time.
            catch (Exception ex)
            {
                App.Current.Services.GetService <IErrorNotifications>().NotifyException("Exception in PickCurrentInputFile", ex);

                throw;
            }

            return(true);
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Open a .sketch360 file
        /// </summary>
        /// <param name="parameter">the parameter is not used.</param>
        /// <returns>an async task</returns>
        protected override async Task ExecuteAsync(object parameter)
        {
            /// Once we stop getting opens with octet-stream, we will remove the file type and only open x-sketch360
            var customFileType =
                new FilePickerFileType(new Dictionary <DevicePlatform, IEnumerable <string> >
            {
                //{ DevicePlatform.Android, new[] { "application/x-sketch360" } },
                { DevicePlatform.Android, new[] { "application/octet-stream", "application/x-sketch360" } },
                { DevicePlatform.UWP, new[] { ".sketch360" } },
            });

            var options = new PickOptions
            {
                PickerTitle = "Please select a Sketch 360 File",
                FileTypes   = customFileType,
            };

            var fileData = await Xamarin.Essentials.FilePicker.PickAsync(options).ConfigureAwait(true);

            if (fileData == null)
            {
                return;
            }

            if (System.IO.Path.GetExtension(fileData.FileName) == ".sketch360")
            {
                using var stream = await fileData.OpenReadAsync().ConfigureAwait(true);

                using var zipFile = new ZipFile(stream);
                var entry = zipFile.GetEntry("sketch360.json");

                using var jsonStream = zipFile.GetInputStream(entry);
                using var reader     = new StreamReader(jsonStream);
                var json = await reader.ReadToEndAsync().ConfigureAwait(true);

                (App.Current as App).LoadSketch(json);
            }

            var properties = new Dictionary <string, string>
            {
                ["filename"]    = fileData.FileName,
                ["contentType"] = fileData.ContentType
            };

            Analytics.TrackEvent("Sketch Opened", properties);
        }
Ejemplo n.º 11
0
        private async void Import_Clicked(object sender, EventArgs e)
        {
            var customFileType =
                new FilePickerFileType(new Dictionary <DevicePlatform, IEnumerable <string> >
            {
                { DevicePlatform.iOS, new[] { "json" } },     // or general UTType values
            });
            var pickResult = await FilePicker.PickAsync(new PickOptions
            {
                PickerTitle = "Select file"
                              //,FileTypes = customFileType
            });

            if (pickResult != null)
            {
                if (pickResult.FileName.EndsWith("json", StringComparison.OrdinalIgnoreCase))
                {
                    var stream = await pickResult.OpenReadAsync();

                    string js = string.Empty;
                    using (StreamReader read = new StreamReader(stream))
                    {
                        js = read.ReadToEnd();
                    }
                    List <string> jsons = new List <string>();
                    jsons.Add(js);
                    if (jsons != null && jsons.Count > 0)
                    {
                        ImportPothiPopup importPothi = new ImportPothiPopup(jsons);
                        await Navigation.PushPopupAsync(importPothi);
                    }
                    else
                    {
                        Util.ShowRoast("No file found");
                    }
                }
                else
                {
                    await DisplayAlert("Wrong file", "Not a valid json file", "OK");
                }
            }
        }
Ejemplo n.º 12
0
        public static PickOptions GetDefaultPickOptions()
        {
            var customFileType = new FilePickerFileType(new Dictionary <DevicePlatform, IEnumerable <string> >
            {
                { DevicePlatform.UWP, null },       // => OK (can select any files)
                { DevicePlatform.Android, null },   // => OK (can select any files)

                { DevicePlatform.iOS, null },       // TODO - it's working ? (can specify any files ?)
                { DevicePlatform.macOS, null },     // TODO - it's working ? (can specify any files ?)

                { DevicePlatform.tvOS, null },      // it's working ? (can specify any files ?)
                { DevicePlatform.Tizen, null },     // it's working ? (can specify any files ?)
                { DevicePlatform.Unknown, null },   // it's working ? (can specify any files ?)
                { DevicePlatform.watchOS, null },   // it's working ? (can specify any files ?)
            });

            var options = new PickOptions
            {
                FileTypes = customFileType
            };

            return(options);
        }