/// <summary>
        /// Get all files paths from chosen folder into "List<string> folder1FileList"
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void btn_folder1_Click(object sender, RoutedEventArgs e)
        {
            IReadOnlyList <StorageFile> fileList = await filePicker.PickMultipleFilesAsync();

            if (fileList != null)
            {
                // clear files list
                if (folder1FileList.Count > 0)
                {
                    folder1FileList.Clear();
                }

                // fill collection
                foreach (var item in fileList)
                {
                    folder1FileList.Add(item.Path);
                }

                // affect label
                string fileParent = Directory.GetParent(fileList[0].Path).FullName.ToString();
                label_folder1.Text = fileParent + "   // Files : " + fileList.Count;
            }
            else
            {
                await new MessageDialog("Something gone wrong, try again...").ShowAsync();
            }
        }
        private async void SharePictureButton_OnClick(object sender, RoutedEventArgs e)
        {
            if (!await Tools.CheckInternetConnectionAsync())
            {
                return;
            }

            FileOpenPicker openPicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary
            };

            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".png");
            var pictures = await openPicker.PickMultipleFilesAsync();

            int num = pictures.Count;
            List <IRandomAccessStream> streams = new List <IRandomAccessStream>();

            foreach (var picture in pictures)
            {
                var stream = await picture.OpenReadAsync();

                streams.Add(stream);
            }

            await TwitterService.Instance.TweetStatusAsync("nihao", streams.ToArray());

            //if (picture != null)
            //{
            //}
        }
Example #3
0
        private async void encodeImages_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker openPicker = new FileOpenPicker();

            foreach (string extension in FileExtensions.Image)
            {
                openPicker.FileTypeFilter.Add(extension);
            }
            IReadOnlyList <StorageFile> files = await openPicker.PickMultipleFilesAsync();

            composition = new MediaComposition();
            foreach (StorageFile file in files)
            {
                m_files.Add(file);
                var clip = await MediaClip.CreateFromImageFileAsync(file, TimeSpan.FromMilliseconds(1000));

                composition.Clips.Add(clip);
            }

            Debug.WriteLine(composition.Clips.Count);
            //StorageFile fileSave = await openPicker.PickSaveFileAsync();
            //if (file != null)
            //{
            //    var saveOperation = composition.RenderToFileAsync(file, MediaTrimmingPreference.Precise);
            //    await composition.RenderToFileAsync("C://Mike");
            //}
        }
        private async void SendFileExecute()
        {
            if (MediaLibrary.SelectedCount > 0)
            {
                foreach (var storage in MediaLibrary.Where(x => x.IsSelected))
                {
                    await SendFileAsync(storage.File, storage.Caption);
                }

                return;
            }

            var picker = new FileOpenPicker();

            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            picker.FileTypeFilter.Add("*");

            var files = await picker.PickMultipleFilesAsync();

            if (files != null && files.Count > 0)
            {
                foreach (var storage in files)
                {
                    await SendFileAsync(storage, null);
                }
            }
        }
Example #5
0
        private async void AddFilesFromDisk(object parameter)
        {
            this.Idle = false;

            var fileOpenPicker = new FileOpenPicker();

            fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
            fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            fileOpenPicker.FileTypeFilter.Add(".png");
            fileOpenPicker.FileTypeFilter.Add(".jpg");
            fileOpenPicker.FileTypeFilter.Add(".jpeg");
            fileOpenPicker.FileTypeFilter.Add(".mp4");
            fileOpenPicker.FileTypeFilter.Add(".avi");
            fileOpenPicker.FileTypeFilter.Add(".mpg");
            var selectedFiles = await fileOpenPicker.PickMultipleFilesAsync();

            var alreadySetSelectedMediaItem = false;

            foreach (var selectedFile in selectedFiles)
            {
                var fileName  = string.Format("{0}-{1}{2}", Path.GetFileNameWithoutExtension(selectedFile.Name), Guid.NewGuid(), Path.GetExtension(selectedFile.Name));
                var localFile = await selectedFile.CopyAsync(_localMediaFolder, fileName);

                var mediaItem = new MediaItem(FolderType.Local, ReservationId, localFile.Name);
                MediaItems.Add(mediaItem);

                if (!alreadySetSelectedMediaItem)
                {
                    SelectedMediaItem           = mediaItem;
                    alreadySetSelectedMediaItem = true;
                }
            }

            this.Idle = true;
        }
        private async void CreateBut_onClick(object sender, RoutedEventArgs e)
        {
            var filesPicker = new FileOpenPicker();

            filesPicker.ViewMode = PickerViewMode.Thumbnail;
            filesPicker.SuggestedStartLocation = PickerLocationId.Desktop;
            filesPicker.FileTypeFilter.Add(".seq");

            IReadOnlyList <StorageFile> filesList = new List <StorageFile>();

            filesList = await filesPicker.PickMultipleFilesAsync();

            if (filesList.Count != 0)
            {
                var requestDialog = new NameRequestDialog();
                var dialogResult  = await requestDialog.ShowAsync();

                if (dialogResult == ContentDialogResult.Primary)
                {
                    var progressDialog = new ProgressDialog("Проводится эксперимент, это может занять несколько минут.\n" +
                                                            "Пожалуйста не закрывайте приложение!");
                    progressDialog.ShowAsync();
                    await JsonWriter.WriteResult(await Experiment.Start(filesList), requestDialog.FileName);

                    UpdateResultsNamesCollection();
                    progressDialog.Hide();
                }
            }
        }
        private async void LoadImagesFromFileClicked(object sender, RoutedEventArgs e)
        {
            this.progressRing.IsActive = true;

            try
            {
                FileOpenPicker fileOpenPicker = new FileOpenPicker {
                    SuggestedStartLocation = PickerLocationId.PicturesLibrary, ViewMode = PickerViewMode.Thumbnail
                };
                fileOpenPicker.FileTypeFilter.Add(".jpg");
                fileOpenPicker.FileTypeFilter.Add(".jpeg");
                fileOpenPicker.FileTypeFilter.Add(".png");
                fileOpenPicker.FileTypeFilter.Add(".bmp");
                IReadOnlyList <StorageFile> selectedFiles = await fileOpenPicker.PickMultipleFilesAsync();

                if (selectedFiles != null)
                {
                    this.OnImageSearchCompleted?.Invoke(this, selectedFiles.Select(file => new ImageAnalyzer(file.OpenStreamForReadAsync, file.Path)));
                }
            }
            catch (Exception ex)
            {
                this.imageResultsGrid.ItemsSource = null;
                await Util.GenericApiCallExceptionHandler(ex, "Failure processing local images");
            }

            this.progressRing.IsActive = false;
        }
Example #8
0
        private async void btnAddProducImgs_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".png");
            //FileData
            var openFile = await openPicker.PickMultipleFilesAsync();

            if (openFile != null)
            {
                foreach (var item in openFile)
                {
                    var Product_Images = new Product_Images()
                    {
                        Name = item.Path
                    };
                    Product.Product_Images.Add(Product_Images);
                    test.Add(Product_Images);
                }
                this.DataContext      = Product;
                lvManyImg.ItemsSource = null;
                lvManyImg.ItemsSource = test;
            }
        }
        async void CopyButton_Click(object sender, RoutedEventArgs e)
        {
            OutputText.Text = "Storage Items: ";
            var filePicker = new FileOpenPicker
            {
                ViewMode       = PickerViewMode.List,
                FileTypeFilter = { "*" }
            };

            var storageItems = await filePicker.PickMultipleFilesAsync();

            if (storageItems.Count > 0)
            {
                OutputText.Text += storageItems.Count + " file(s) are copied into clipboard";
                var dataPackage = new DataPackage();
                dataPackage.SetStorageItems(storageItems);

                // Request a copy operation from targets that support different file operations, like File Explorer
                dataPackage.RequestedOperation = DataPackageOperation.Copy;
                try
                {
                    Windows.ApplicationModel.DataTransfer.Clipboard.SetContent(dataPackage);
                }
                catch (Exception ex)
                {
                    // Copying data to Clipboard can potentially fail - for example, if another application is holding Clipboard open
                    rootPage.NotifyUser("Error copying content to Clipboard: " + ex.Message + ". Try again", NotifyType.ErrorMessage);
                }
            }
            else
            {
                OutputText.Text += "No file was selected.";
            }
        }
Example #10
0
        private async void ImportFiles(bool appendFiles = false)
        {
            try
            {
                Helper.DontUseTimersAndOtherStuff = true;
                FileOpenPicker openPicker = new FileOpenPicker
                {
                    ViewMode = PickerViewMode.Thumbnail,
                    SuggestedStartLocation = PickerLocationId.PicturesLibrary
                };
                openPicker.FileTypeFilter.Add(".jpg");
                openPicker.FileTypeFilter.Add(".jpeg");
                openPicker.FileTypeFilter.Add(".bmp");
                //openPicker.FileTypeFilter.Add(".gif");
                openPicker.FileTypeFilter.Add(".png");
                openPicker.FileTypeFilter.Add(".mp4");
                //openPicker.FileTypeFilter.Add(".mkv");
                var files = await openPicker.PickMultipleFilesAsync();

                Helper.DontUseTimersAndOtherStuff = false;
                ImportFiles(files, appendFiles);
            }
            catch (Exception ex)
            {
                ex.PrintException("ImportButtonClick");
                Helper.ShowErr("ImportButtonClick", ex);
                Helper.DontUseTimersAndOtherStuff = false;
            }
        }
Example #11
0
        private async void Photopicker_Click(object sender, RoutedEventArgs e)
        {
            //OutputTextBlock.Text = "";

            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.ViewMode = PickerViewMode.List;
            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            openPicker.FileTypeFilter.Add("*");
            IReadOnlyList <StorageFile> files = await openPicker.PickMultipleFilesAsync();

            if (files.Count > 0)
            {
                StringBuilder output = new StringBuilder("Picked files:\n");
                // Application now has read/write access to the picked file(s)
                foreach (StorageFile file in files)
                {
                    output.Append(file.Name + "\n");
                }
                // OutputTextBlock.Text = output.ToString();
            }
            else
            {
                // OutputTextBlock.Text = "Operation cancelled.";
            }
        }
Example #12
0
        /// <summary>
        /// Adds a file to the end of the playlist loaded in PickPlaylistButton_Click
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        async private void PickAudioButton_Click(object sender, RoutedEventArgs e)
        {
            if (MainPage.playlist != null)
            {
                FileOpenPicker picker             = MainPage.CreateFilePicker(MainPage.audioExtensions);
                IReadOnlyList <StorageFile> files = await picker.PickMultipleFilesAsync();

                if (files != null && files.Count > 0)
                {
                    foreach (StorageFile file in files)
                    {
                        MainPage.playlist.Files.Add(file);
                    }

                    try
                    {
                        await MainPage.playlist.SaveAsync();

                        this.OutputStatus.Text = files.Count + " files added to playlist.";
                    }
                    catch (Exception error)
                    {
                        this.OutputStatus.Text = error.Message;
                    }
                }
                else
                {
                    this.OutputStatus.Text = "No files picked.";
                }
            }
            else
            {
                this.OutputStatus.Text = "Pick playlist first.";
            }
        }
Example #13
0
        private async void btnPickFiles_Click(object sender, RoutedEventArgs e)
        {
            // 选择多个文件
            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.ViewMode = PickerViewMode.List;
            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            openPicker.FileTypeFilter.Add("*");

            // 弹出文件选择窗口
            IReadOnlyList <StorageFile> files = await openPicker.PickMultipleFilesAsync(); // 用户在“文件选择窗口”中完成操作后,会返回对应的 StorageFile 对象

            if (files.Count > 0)
            {
                lblMsg.Text  = "选中文件: ";
                lblMsg.Text += Environment.NewLine;
                foreach (StorageFile file in files)
                {
                    lblMsg.Text += (file.Name);
                    lblMsg.Text += Environment.NewLine;
                }
            }
            else
            {
                lblMsg.Text = "取消了";
            }
        }
Example #14
0
        //打开filePicker,读入文件到 mediaFileInfos;
        private async void FileButton_ClickAsy(object sender, RoutedEventArgs e)
        {
            FileOpenPicker fileOpenPicker = new FileOpenPicker();

            fileOpenPicker.ViewMode = PickerViewMode.Thumbnail;
            fileOpenPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
            fileOpenPicker.FileTypeFilter.Add(".mp3");
            fileOpenPicker.FileTypeFilter.Add(".mp4");

            IReadOnlyList <StorageFile> mediaFiles = await fileOpenPicker.PickMultipleFilesAsync();

            if (mediaFiles != null)
            {
                foreach (StorageFile mediaFile in mediaFiles)
                {
                    Title.Text += mediaFile.Name;
                    this.mediaFileInfos.Add(new MediaFileInfo(mediaFile));
                    FileBlock.Items.Add(mediaFile.Name);
                }
            }
            else
            {
                Title.Text = "error open!";
            }

            //foreach (MediaFileInfo mediaFile in this.mediaFileInfos)
            //{
            //    Title.Text += mediaFile.name;
            //}
        }
Example #15
0
        public async Task <List <MediaFile> > PickPhotosAsync(PickMediaOptions options = null, MultiPickerOptions pickerOptions = null, CancellationToken token = default(CancellationToken))
        {
            var picker = new FileOpenPicker();

            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.ViewMode = PickerViewMode.Thumbnail;

            foreach (var filter in SupportedImageFileTypes)
            {
                picker.FileTypeFilter.Add(filter);
            }

            var result = await picker.PickMultipleFilesAsync();

            if (result == null)
            {
                return(null);
            }

            var ret = new List <MediaFile>();

            foreach (var file in result)
            {
                ret.Add(await MediaFileFromFile(file));
            }

            return(ret);
        }
Example #16
0
        private async void AddImageClicked(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker();

            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".png");
            picker.FileTypeFilter.Add(".gif");
            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.SettingsIdentifier     = loader.GetString("CreateTweetPage_FilePickerTitle");

            var files = await picker.PickMultipleFilesAsync();

            foreach (var file in files)
            {
                if (viewModel.Images.Count < 4)
                {
                    try
                    {
                        viewModel.Images.Add(new SendableImage(file));
                    }
                    catch (Exception ex)
                    {
                        var message = new MessageDialog(ex.Message, loader.GetString("ErrorTitle1"));
                    }
                }
                else
                {
                    var message = new MessageDialog(loader.GetString("CreateTweetPage_FilePickerError"), loader.GetString("ErrorTitle1"));
                }
            }
        }
Example #17
0
        private async void OnSelectFile(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;

            button.IsEnabled = false;

            try
            {
                var picker = new FileOpenPicker
                {
                    SuggestedStartLocation = PickerLocationId.VideosLibrary,
                    ViewMode = PickerViewMode.Thumbnail
                };

                picker.FileTypeFilter.Add(".mp4");
                picker.FileTypeFilter.Add(".mov");
                picker.FileTypeFilter.Add(".wmv");
                picker.FileTypeFilter.Add(".avi");

                var files = await picker.PickMultipleFilesAsync();

                await SetSourceFilesAsync(files);
            }
            finally
            {
                button.IsEnabled = true;
            }
        }
        private async void PickFonts()
        {
            var picker = new FileOpenPicker();

            foreach (var format in FontFinder.SupportedFormats)
            {
                picker.FileTypeFilter.Add(format);
            }

            picker.CommitButtonText = Localization.Get("FilePickerConfirm");
            var files = await picker.PickMultipleFilesAsync();

            if (files.Any())
            {
                ViewModel.IsLoadingFonts = true;
                try
                {
                    if (await FontFinder.ImportFontsAsync(files.ToList()) is FontImportResult result &&
                        result.Imported.Count > 0)
                    {
                        ViewModel.RefreshFontList();
                        ViewModel.TrySetSelectionFromImport(result);
                    }
                }
                finally
                {
                    ViewModel.IsLoadingFonts = false;
                }
            }
        }
        private async Task AddLog()
        {
            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.ViewMode = PickerViewMode.List;
            openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
            openPicker.FileTypeFilter.Add(".dat");

            IReadOnlyList <StorageFile> files = ImmutableArray <StorageFile> .Empty;
            await DispatcherHelper.ExecuteOnUIThreadAsync(async() => { files = await openPicker.PickMultipleFilesAsync(); });

            if (files.Count > 0)
            {
                Busy.MaxProgressValue = files.Count;
                Busy.ProgressValue    = 0;
                foreach (StorageFile file in files)
                {
                    Busy.Message = $"Importiere Datei {file.Name}";
                    BatNode node = await _batProjectManager.AddNode(_project, file);

                    await DispatcherHelper.ExecuteOnUIThreadAsync(() =>
                    {
                        _logs.Add(new NodeViewModel(_project, node, _navigationService, this));
                    });

                    Busy.ProgressValue++;
                }
            }
        }
Example #20
0
        private async void Insert_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker Picker = new FileOpenPicker
            {
                CommitButtonText       = "插入附件",
                SuggestedStartLocation = PickerLocationId.Desktop,
                ViewMode = PickerViewMode.Thumbnail
            };

            Picker.FileTypeFilter.Add("*");
            if ((await Picker.PickMultipleFilesAsync()) is IReadOnlyList <StorageFile> FileList)
            {
                foreach (var File in FileList)
                {
                    var attachment = new MimePart(File.ContentType, File.FileType)
                    {
                        Content                 = new MimeContent(await File.OpenStreamForReadAsync(), ContentEncoding.Default),
                        ContentDisposition      = new ContentDisposition(ContentDisposition.Attachment),
                        ContentTransferEncoding = ContentEncoding.Base64,
                        FileName                = File.Name
                    };
                    Attachments.Add(attachment);
                }
                InsertText.Text = "(共" + Attachments.Count + "个)";
            }
        }
Example #21
0
        async void PickFilesButton_Click(object sender, RoutedEventArgs e)
        {
            // Clear any previously returned files between iterations of this scenario

            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.ViewMode = PickerViewMode.List;
            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            openPicker.FileTypeFilter.Add("*");
            IReadOnlyList <StorageFile> files = await openPicker.PickMultipleFilesAsync();

            if (files.Count > 0)
            {
                StringBuilder output    = new StringBuilder("Chosen files:\n");
                StringBuilder filepaths = new StringBuilder();
                // Application now has read/write access to the picked file(s)
                foreach (StorageFile file in files)
                {
                    output.Append(file.Name + "\n");
                    filepaths.Append(file.Path + "\n");
                }
                OutputTextBlock.Text = output.ToString();
                FilePathBox.Text     = filepaths.ToString();
            }
            else
            {
                OutputTextBlock.Text = "Operation cancelled.";
            }
        }
Example #22
0
        private async void Select_OnClick(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker {
                SuggestedStartLocation = PickerLocationId.Desktop
            };

            picker.FileTypeFilter.Add(".mp4");

            var pickedFiles = await picker.PickMultipleFilesAsync();

            if (pickedFiles == null)
            {
                return;
            }

            TextBlock.Text = $"Importing {pickedFiles.Count} files";

            composition = new MediaComposition();
            var files = pickedFiles.OrderBy(x => x.Name).ToArray();

            foreach (var file in files)
            {
                var clip = await MediaClip.CreateFromFileAsync(file);

                composition.Clips.Add(clip);
                TextBlock.Text = $"Importing {Path.GetFileName(file.Path)}";
            }

            TextBlock.Text = $"All files are imported";
        }
        private async void SelectFilesButtonClick(object sender, RoutedEventArgs e)
        {
            var filePicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary
            };

            filePicker.FileTypeFilter.Add(".jpg");
            filePicker.FileTypeFilter.Add(".jpeg");
            SelectedFiles = await filePicker.PickMultipleFilesAsync();

            if (SelectedFiles == null)
            {
                UploadButton.IsEnabled = false;
                return;
            }

            if (SelectedFiles.Count > 10)
            {
                "Only 10 files can select".ShowERR();
                SelectedFiles          = null;
                UploadButton.IsEnabled = false;
            }
            else
            {
                UploadButton.IsEnabled = true;
            }
        }
        private async Task ExecuteAsync(FileOpenPickerNotification fileOpenPickerNotification)
        {
            var picker = new FileOpenPicker();

            if (fileOpenPickerNotification.FileTypeFilter != null)
            {
                foreach (var fileType in fileOpenPickerNotification.FileTypeFilter)
                {
                    picker.FileTypeFilter.Add(fileType);
                }
            }

            picker.SuggestedStartLocation = fileOpenPickerNotification.SuggestedStartLocation;
            picker.ViewMode = fileOpenPickerNotification.ViewMode;

            if (fileOpenPickerNotification.IsMultiple)
            {
                fileOpenPickerNotification.Result = await picker.PickMultipleFilesAsync();
            }
            else
            {
                var result = await picker.PickSingleFileAsync();

                fileOpenPickerNotification.Result = result != null ? new[] { result } : Enumerable.Empty <StorageFile>();
            }
        }
Example #25
0
        private async void btn_OpenFilePlay_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.CommitButtonText       = "选中此文件";
            openPicker.ViewMode               = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
            openPicker.FileTypeFilter.Add(".mp3");
            openPicker.FileTypeFilter.Add(".mp4");
            openPicker.FileTypeFilter.Add(".flv");
            openPicker.FileTypeFilter.Add(".avi");
            openPicker.FileTypeFilter.Add(".wmv");
            openPicker.FileTypeFilter.Add(".ogv");
            openPicker.FileTypeFilter.Add(".wkv");
            openPicker.FileTypeFilter.Add(".3gp");
            openPicker.FileTypeFilter.Add(".rmvb");
            // 弹出文件选择窗口
            var files = await openPicker.PickMultipleFilesAsync(); // 用户在“文件选择窗口”中完成操作后,会返回对应的 StorageFile 对象

            if (files == null || files.Count == 0)
            {
                return;
            }
            List <PlayerModel> ls = new List <PlayerModel>();

            foreach (StorageFile file in files)
            {
                ls.Add(new PlayerModel()
                {
                    Mode = PlayMode.FormLocal, No = "1", VideoTitle = "", Title = file.DisplayName, Parameter = file, Aid = file.DisplayName, Mid = file.Path
                });
            }
            play_frame.Navigate(typeof(PlayerPage), new object[] { ls, 0 });
        }
        private async void More_Click(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker();

            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.AddRange(Constants.MediaTypes);

            var files = await picker.PickMultipleFilesAsync();

            if (files != null)
            {
                foreach (var file in files)
                {
                    if (Path.GetExtension(file.Name).Equals(".mp4"))
                    {
                        //Items.Add(new StorageVideo(file));
                    }
                    else
                    {
                        Items.Add(new StoragePhoto(file));
                    }
                }
            }

            Remove.IsEnabled = Items.Count > 1;
        }
Example #27
0
        private async Task <List <JSValueObject> > PickMultipleFileAsync(FileOpenPicker picker, bool cache, bool readContent)
        {
            TaskCompletionSource <List <JSValueObject> > tcs = new TaskCompletionSource <List <JSValueObject> >();

            await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async() =>
            {
                IReadOnlyList <StorageFile> files = await picker.PickMultipleFilesAsync();
                if (files.Count > 0)
                {
                    List <JSValueObject> jarrayObj = new List <JSValueObject>();
                    foreach (var file in files)
                    {
                        var processedFile = await PrepareFile(file, cache, readContent);
                        jarrayObj.Add(processedFile);
                    }

                    tcs.SetResult(jarrayObj);
                }
                else
                {
                    tcs.SetResult(new List <JSValueObject>());
                }
            });

            var result = await tcs.Task;

            return(result);
        }
Example #28
0
        public async Task <IEnumerable <Document> > Open()
        {
            var docs       = new List <Document>();
            var filepicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.List,
                SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
                FileTypeFilter         = { ".md", ".mdown", ".markdown", ".mkd" }
            };

            var files = await filepicker.PickMultipleFilesAsync();

            foreach (var file in files)
            {
                var d = new LocalDocument(file);
                await d.Load();

                docs.Add(d);

                string token = StorageApplicationPermissions.FutureAccessList.Add(file, file.Name);
                _localSettings.Values[file.Name] = token;
                d.Token = token;
            }

            return(docs);
        }
        private async void SelectFilesButton_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker filePicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.List,
                SuggestedStartLocation = PickerLocationId.DocumentsLibrary,
                FileTypeFilter         = { "*" }
            };

            IReadOnlyList <StorageFile> pickedFiles = await filePicker.PickMultipleFilesAsync();

            if (pickedFiles.Count > 0)
            {
                this.storageItems = pickedFiles;

                // Display the file names in the UI.
                string selectedFiles = String.Empty;
                for (int index = 0; index < pickedFiles.Count; index++)
                {
                    selectedFiles += pickedFiles[index].Name;

                    if (index != (pickedFiles.Count - 1))
                    {
                        selectedFiles += ", ";
                    }
                }
                this.rootPage.NotifyUser("Picked files: " + selectedFiles + ".", NotifyType.StatusMessage);

                ShareStep.Visibility = Visibility.Visible;
            }
        }
        private async void PickFilesButton_Click(object sender, RoutedEventArgs e)
        {
            // Clear any previously returned files between iterations of this scenario
            OutputTextBlock.Text = "";

            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.ViewMode = PickerViewMode.List;
            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            openPicker.FileTypeFilter.Add("*");
            IReadOnlyList <StorageFile> files = await openPicker.PickMultipleFilesAsync();

            if (files.Count > 0)
            {
                StringBuilder output = new StringBuilder("Picked files:\n");
                // The StorageFiles have read/write access to the picked files.
                // See the FileAccess sample for code that uses a StorageFile to read and write.
                foreach (StorageFile file in files)
                {
                    output.Append(file.Name + "\n");
                }
                OutputTextBlock.Text = output.ToString();
            }
            else
            {
                OutputTextBlock.Text = "Operation cancelled.";
            }
        }
Example #31
0
        private async Task<IReadOnlyList<IFile>> OpenFilesAsync( OpenFileInteraction openFile )
        {
            Contract.Requires( openFile != null );
            Contract.Ensures( Contract.Result<Task<IReadOnlyList<IFile>>>() != null );

            var saveButton = openFile.DefaultCommand;
            var dialog = new FileOpenPicker();

            dialog.FileTypeFilter.AddRange( openFile.FileTypeFilter.FixUpExtensions() );
            dialog.SuggestedStartLocation = SuggestedStartLocation;
            dialog.ViewMode = ViewMode;

            if ( !string.IsNullOrEmpty( SettingsIdentifier ) )
                dialog.SettingsIdentifier = SettingsIdentifier;

            if ( saveButton != null )
                dialog.CommitButtonText = saveButton.Name;

            if ( openFile.Multiselect )
                return ( await dialog.PickMultipleFilesAsync() ).Select( f => f.AsFile() ).ToArray();

            var file = await dialog.PickSingleFileAsync();

            if ( file != null )
                return new[] { file.AsFile() };

            return new IFile[0];
        }