當前位置: 首頁>>代碼示例>>C#>>正文


C# FileOpenPicker.PickMultipleFilesAsync方法代碼示例

本文整理匯總了C#中Windows.Storage.Pickers.FileOpenPicker.PickMultipleFilesAsync方法的典型用法代碼示例。如果您正苦於以下問題:C# FileOpenPicker.PickMultipleFilesAsync方法的具體用法?C# FileOpenPicker.PickMultipleFilesAsync怎麽用?C# FileOpenPicker.PickMultipleFilesAsync使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Windows.Storage.Pickers.FileOpenPicker的用法示例。


在下文中一共展示了FileOpenPicker.PickMultipleFilesAsync方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: AddButtonClick_OnClick

        private async void AddButtonClick_OnClick(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker();
            picker.FileTypeFilter.Add(".jpg");
            var files = await picker.PickMultipleFilesAsync();

            TreeMap.Children.Clear();

            var sources = new List<BitmapImage>();
            foreach (var file in files)
            {
                var stream = (await file.OpenStreamForReadAsync()).AsRandomAccessStream();//await file.GetScaledImageAsThumbnailAsync(ThumbnailMode.PicturesView, 300);
                var imageSource = new BitmapImage();
                await imageSource.SetSourceAsync(stream);

                sources.Add(imageSource);

                var image = new Image();
                image.Stretch = Stretch.UniformToFill;
                image.Source = imageSource;
                TreeMap.Children.Add(image);
            }

            MosaicImage.Source = sources;
        }
開發者ID:nguyenkien,項目名稱:MosaicImageControls,代碼行數:25,代碼來源:MainPage.xaml.cs

示例2: CopyButton_Click

        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.";
            }
        }
開發者ID:mbin,項目名稱:Win81App,代碼行數:33,代碼來源:CopyFile.xaml.cs

示例3: SelectFilesButton_Click

        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;
            }
        }
開發者ID:oldnewthing,項目名稱:old-Windows8-samples,代碼行數:31,代碼來源:ShareFiles.xaml.cs

示例4: ImportEPubAsync

        public static async Task<bool> ImportEPubAsync()
        {
            try
            {
                var ePubPicker = new FileOpenPicker();
                ePubPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                ePubPicker.FileTypeFilter.Add(".epub");

                var files = await ePubPicker.PickMultipleFilesAsync();

                if (files.Count > 0)
                {
                    var ePubDirectory = await ApplicationData.Current.RoamingFolder.GetFolderAsync("ePubs");

                    foreach (var file in files)
                    {
                        var fileDirectory = await ePubDirectory.CreateFolderAsync($"{file.DisplayName}.{DateTime.Now.ToFileTime()}");
                        var copiedFile = await file.CopyAsync(fileDirectory);
                        await Task.Run(() => ZipFile.ExtractToDirectory(copiedFile.Path, fileDirectory.Path));
                    }
                }

                return true;
            }

            catch
            {
                return false;
            }
        }
開發者ID:RareNCool,項目名稱:EPubReader,代碼行數:30,代碼來源:ImportController.cs

示例5: Button_Click_1

        private async void Button_Click_1(object sender, RoutedEventArgs e)
        {
            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.ViewMode = PickerViewMode.List;
            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;

            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".png");
            
            IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();

            foreach(var file in files)
            {
                var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                BitmapImage image = new BitmapImage();
                image.SetSource(stream);

                ImageData data = new ImageData();
                data.image = image;
                data.name = file.DisplayName;

                this._list.Add(data);
            }
        }
開發者ID:coelacanth77,項目名稱:MultiFilePickerSample,代碼行數:26,代碼來源:MainPage.xaml.cs

示例6: OpenFileButtonOnTapped

        private async void OpenFileButtonOnTapped(object sender, TappedRoutedEventArgs e)
        {
            var filePicker = new FileOpenPicker { SuggestedStartLocation = PickerLocationId.DocumentsLibrary };
            filePicker.FileTypeFilter.Add("*");

	        var files = await filePicker.PickMultipleFilesAsync();
			if (files == null || files.Count == 0) return;

			foreach (var file in files)
	        {
		        try
		        {
					var storeStream = await file.OpenAsync(FileAccessMode.Read);
					var dicomFile = DicomFile.Open(storeStream.AsStream());
			        var fileImage = new DicomFileImage(Path.GetFileNameWithoutExtension(file.Path), file, dicomFile);

			        var modality = fileImage.Modality;
			        var modalityGroup = _modalityGroups.FirstOrDefault(m => m.Modality.Equals(modality));
					if (modalityGroup == null)
					{
						_modalityGroups.Add(new ModalityGroup { Modality = modality, FileImages = new ObservableCollection<DicomFileImage> { fileImage }});
					}
					else
					{
						modalityGroup.FileImages.Add(fileImage);
					}
		        }
		        catch
		        {
		        }
	        }

		}
開發者ID:1danielcoelho,項目名稱:FellowOakDicomTesting,代碼行數:33,代碼來源:MainPage.xaml.cs

示例7: btnFilePicker_Click

        private async void btnFilePicker_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();
            if (files != null && files.Count > 0)
            {
                string output = "";

                foreach (StorageFile file in files)
                {
                    output += file.Name + Environment.NewLine;
                }
                tbPickedFiles.Text = output;

                if (this.noteFileList != null)
                {
                    this.noteFileList.AddRange(files);
                }
                else
                {
                    this.noteFileList = new List<StorageFile>();
                    this.noteFileList.AddRange(files);
                }
            }
            else
            {
                tbPickedFiles.Text = "";
            }
        }
開發者ID:gulyu,項目名稱:SmartNote,代碼行數:32,代碼來源:MainPage.xaml.cs

示例8: BrowseForImages

        private async void BrowseForImages()
        {            
            StatusText = "Running...";
            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.CommitButtonText = "Open";
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpe");
            openPicker.FileTypeFilter.Add(".bmp");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".gif");
            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            IReadOnlyList<StorageFile> files = await openPicker.PickMultipleFilesAsync();

            if (files.Count > 0)
            {
                ResultsList.Clear();
            }
            foreach (StorageFile file in files)
            {
                try
                {
                    var result = await ProcessImage(file);
                    ResultsList.Add(result);
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex);
                }
            }
            StatusText = "Ready";
        }
開發者ID:pingzing,項目名稱:SimpleOcr10,代碼行數:32,代碼來源:MainPageViewModel.cs

示例9: PickFilesButton_Click

        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");
                // 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.";
            }
        }
開發者ID:RasmusTG,項目名稱:Windows-universal-samples,代碼行數:25,代碼來源:Scenario2_MultiFile.xaml.cs

示例10: Add_OnClick

        private async void Add_OnClick(object sender, RoutedEventArgs e)
        {
            var btn = sender as Button;
            var tool = (string)btn.Content;

            FileOpenPicker openPicker = new FileOpenPicker();

            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".gif");

            var storageFiles = await openPicker.PickMultipleFilesAsync();
            if (storageFiles == null)
            {
                await new MessageDialog("請選擇圖片").ShowAsync();
                return;
            }

            this.progressRing.IsActive = true;

            byte[] content = null;

            // 獲取指定的文件的文本內容

            var count = 0;
            foreach (var storageFile in storageFiles)
            {
                IRandomAccessStreamWithContentType accessStream = await storageFile.OpenReadAsync();

                var fileName = storageFile.Name;

                using (Stream stream = accessStream.AsStreamForRead((int)accessStream.Size))
                {
                    content = new byte[stream.Length];
                    await stream.ReadAsync(content, 0, (int)stream.Length);
                }

                var fileData = new List<KeyValuePair<string, byte[]>>();
                fileData.Add(new KeyValuePair<string, byte[]>(fileName, content));


                var repository = new RepositoryAsync();
                var users = await repository.GetRandomUsers(1);

                var user = users.FirstOrDefault();

                var api = new UArticleService();

                var result = await api.CreateUArticle(user.UserId, user.SessionId, "testtitle", "", tool, fileData);
                if (result.Success)
                {
                    count++;
                }
            }

            this.progressRing.IsActive = false;

            await new MessageDialog($"{count}個樂圖成功創建").ShowAsync();
        }
開發者ID:BiaoLiu,項目名稱:YLP.UWP.TOOLS,代碼行數:59,代碼來源:AddUArticlePage.xaml.cs

示例11: UploadBackgroundAmazon

 public async Task UploadBackgroundAmazon()
 {
     FileOpenPicker openPicker = new FileOpenPicker();
     openPicker.ViewMode = PickerViewMode.Thumbnail;
     openPicker.FileTypeFilter.Add("*");
     IReadOnlyList<StorageFile> file = await openPicker.PickMultipleFilesAsync();
     if(file!=null)
         await AmazonUploadFile(file);
 }
開發者ID:prashanthganathe,項目名稱:PersonalProjects,代碼行數:9,代碼來源:AudienceInfo.xaml.cs

示例12: PickMultipleFilesAsync

async public void PickMultipleFilesAsync()
{
    FileOpenPicker picker = new FileOpenPicker();
    picker.FileTypeFilter.Add(".png");
    picker.FileTypeFilter.Add(".jpg");
    picker.FileTypeFilter.Add(".gif");
    picker.FileTypeFilter.Add(".bmp");
    picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
    picker.ViewMode = PickerViewMode.Thumbnail;
    IReadOnlyList<StorageFile> files = await picker.PickMultipleFilesAsync();
}
開發者ID:BeyondVincent,項目名稱:WindowsStoreAppCode,代碼行數:11,代碼來源:MainPage.xaml.cs

示例13: MultipleFilePicker_Click

 private async void MultipleFilePicker_Click(object sender, RoutedEventArgs e)
 {
     FileOpenPicker picker = new FileOpenPicker();
     picker.FileTypeFilter.Add(".png");
     picker.FileTypeFilter.Add(".jpg");
     picker.FileTypeFilter.Add(".gif");
     picker.FileTypeFilter.Add(".bmp");
     picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
     picker.ViewMode = PickerViewMode.Thumbnail;
     IReadOnlyList<StorageFile> files = await picker.PickMultipleFilesAsync();
 }
開發者ID:Jxperez,項目名稱:31DaysOfWindows8,代碼行數:11,代碼來源:MainPage.xaml.cs

示例14: OpenFiles

 //select files to play through a play picker
 private async void OpenFiles()
 {
     FileOpenPicker fileOpenPicker = new FileOpenPicker();
     // Filter to include a sample subset of file types
     fileOpenPicker.FileTypeFilter.Add(".mp3");
     fileOpenPicker.FileTypeFilter.Add(".wma");
     fileOpenPicker.FileTypeFilter.Add(".flac");
     fileOpenPicker.FileTypeFilter.Add(".m4a");
     fileOpenPicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;
     IReadOnlyList<StorageFile> files = await fileOpenPicker.PickMultipleFilesAsync();
     //add files to playlist
     if (files.Count != 0)
             await AcceptFiles(files);
 }
開發者ID:MichaelAi,項目名稱:Aural-Player,代碼行數:15,代碼來源:MainViewModel.cs

示例15: PickMultipleFilesAsync

		/// <summary>
		/// Opens a file picker and allows the user to pick multiple files and return a list of the files the user chose
		/// </summary>
		/// <param name="location"></param>
		/// <param name="filterTypes"></param>
		/// <returns></returns>
		public async Task<IReadOnlyList<StorageFile>> PickMultipleFilesAsync(
			PickerLocationId location = PickerLocationId.DocumentsLibrary, params string[] filterTypes)
		{
			FileOpenPicker openPicker = new FileOpenPicker();

			openPicker.SuggestedStartLocation = location;

			if (filterTypes != null)
			{
				foreach (string filterType in filterTypes)
				{
					openPicker.FileTypeFilter.Add(filterType);
				}
			}

			return await openPicker.PickMultipleFilesAsync();
		}
開發者ID:karolszmaj,項目名稱:StyleMVVM,代碼行數:23,代碼來源:FilePickerService.cs


注:本文中的Windows.Storage.Pickers.FileOpenPicker.PickMultipleFilesAsync方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。