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


C# FileOpenPicker.PickSingleFileAsync方法代碼示例

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


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

示例1: ButtonFilePick_Click

        private async void ButtonFilePick_Click(object sender, RoutedEventArgs e)
        {
            var picker = new FileOpenPicker();
            picker.ViewMode = PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");

            StorageFile file = await picker.PickSingleFileAsync();


            if (file != null)
            {

                ImageProperties imgProp = await file.Properties.GetImagePropertiesAsync();
                var savedPictureStream = await file.OpenAsync(FileAccessMode.Read);

                //set image properties and show the taken photo
                bitmap = new WriteableBitmap((int)imgProp.Width, (int)imgProp.Height);
                await bitmap.SetSourceAsync(savedPictureStream);
                BBQImage.Source = bitmap;
                BBQImage.Visibility = Visibility.Visible;

                (this.DataContext as BBQRecipeViewModel).imageSource = file.Path;
            }
        }
開發者ID:cheahengsoon,項目名稱:Windows10UWP-HandsOnLab,代碼行數:27,代碼來源:BBQRecipePage.xaml.cs

示例2: MenuItem_Click

        private async void MenuItem_Click(object sender, RoutedEventArgs e)
        {
            StorageFile file;
            var item = sender as MenuFlyoutItem;
            if (item.Tag.ToString() == "photo")
            {
                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.ViewMode = PickerViewMode.Thumbnail;
                openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                openPicker.FileTypeFilter.Add(".jpg");
                openPicker.FileTypeFilter.Add(".jpeg");
                openPicker.FileTypeFilter.Add(".png");

                file = await openPicker.PickSingleFileAsync();
            }
            else
            {
                CameraCaptureUI captureUI = new CameraCaptureUI();
                captureUI.PhotoSettings.Format = CameraCaptureUIPhotoFormat.Jpeg;
                captureUI.PhotoSettings.CroppedSizeInPixels = new Size(200, 200);

                file = await captureUI.CaptureFileAsync(CameraCaptureUIMode.Photo);
            }
            if (file != null)
            {
                // Application now has read/write access to the picked file
                var img = await UtilityHelper.LoadImage(file);
                imgSource.Source = img;
                fileStream = await file.OpenStreamForWriteAsync();
            }
        }
開發者ID:poumason,項目名稱:DotblogsSampleCode,代碼行數:31,代碼來源:MainPage.xaml.cs

示例3: LoadImageUsingSetSource_Click

        private async void LoadImageUsingSetSource_Click(object sender, RoutedEventArgs e)
        {
            // This method loads an image into the WriteableBitmap using the SetSource method

            FileOpenPicker picker = new FileOpenPicker();
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".png");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".bmp");

            StorageFile file = await picker.PickSingleFileAsync();

            // Ensure a file was selected
            if (file != null)
            {
                // Set the source of the WriteableBitmap to the image stream
                using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    try
                    {
                        await Scenario4WriteableBitmap.SetSourceAsync(fileStream);
                    }
                    catch (TaskCanceledException)
                    {
                        // The async action to set the WriteableBitmap's source may be canceled if the user clicks the button repeatedly
                    }
                }
            }
        }
開發者ID:oldnewthing,項目名稱:old-Windows8-samples,代碼行數:30,代碼來源:Scenario4.xaml.cs

示例4: BackgroundButton_Click

      private async void BackgroundButton_Click(object sender, RoutedEventArgs e)
      {
        // Clear previous returned file name, if it exists, between iterations of this scenario
        OutputTextBlock.Text = "";

        FileOpenPicker openPicker = new FileOpenPicker();
        openPicker.ViewMode = PickerViewMode.Thumbnail;
        openPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
        openPicker.FileTypeFilter.Add(".jpg");
        openPicker.FileTypeFilter.Add(".jpeg");
        openPicker.FileTypeFilter.Add(".png");
        StorageFile file = await openPicker.PickSingleFileAsync();
        if (file != null)
        {
          // Application now has read/write access to the picked file
          OutputTextBlock.Text = "Picked photo: " + file.Name;

          BitmapImage img = new BitmapImage();
          img = await ImageHelpers.LoadImage( file );
          MyPicture.Source = img;

        }
        else
        {
          OutputTextBlock.Text = "Operation cancelled.";
        }
      }
開發者ID:underhilld2,項目名稱:BedSideClock,代碼行數:27,代碼來源:StartupPage.xaml.cs

示例5: OpenPicture_Click

        /// <summary>
        /// Open the image selection standard dialog
        /// </summary>
        /// <param name="sender">event sender</param>
        /// <param name="e">event argument</param>
        private async void OpenPicture_Click(object sender, RoutedEventArgs e)
        {
            if (!this.showInProgress)
            {
                this.showInProgress = true;

                try
                {
                    var picker = new FileOpenPicker();

                    picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                    picker.ViewMode = PickerViewMode.Thumbnail;
                    picker.FileTypeFilter.Add(".jpg");
                    picker.FileTypeFilter.Add(".jpeg");

                    var file = await picker.PickSingleFileAsync();
                    if (file != null)
                    {
                        // open captured file and set the image source on the control
                        this.ocrData.PhotoStream = await file.OpenAsync(FileAccessMode.Read);
                    }
                }
                finally
                {
                    this.showInProgress = false;
                }
            }
        }
開發者ID:eirikdal,項目名稱:ReciCamApp,代碼行數:33,代碼來源:PhotoSelector.xaml.cs

示例6: LoadKML

        public async System.Threading.Tasks.Task LoadKML(System.Collections.Generic.List<Windows.Devices.Geolocation.BasicGeoposition> mapdata)
        {
            Windows.Data.Xml.Dom.XmlLoadSettings loadSettings = new Windows.Data.Xml.Dom.XmlLoadSettings();
            loadSettings.ElementContentWhiteSpace = false;
            Windows.Data.Xml.Dom.XmlDocument kml = new Windows.Data.Xml.Dom.XmlDocument();
            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.ViewMode = PickerViewMode.List;
            openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            openPicker.FileTypeFilter.Add(".kml");
            Windows.Storage.IStorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                string[] stringSeparators = new string[] { ",17" };
                kml = await Windows.Data.Xml.Dom.XmlDocument.LoadFromFileAsync(file);
                var element = kml.GetElementsByTagName("coordinates").Item(0);
                string ats  = element.FirstChild.GetXml();

                string[] atsa = ats.Split(stringSeparators, StringSplitOptions.RemoveEmptyEntries);
                int size = atsa.Length-1;
                for (int i = 0; i < size; i++)
                {
                    string[] coord = atsa[i].Split(',');
                    double longi = Convert.ToDouble(coord[0]);
                    double lati = Convert.ToDouble(coord[1]);
                    mapdata.Add(new Windows.Devices.Geolocation.BasicGeoposition() { Latitude = lati, Longitude = longi });
                }
            }
        }
開發者ID:justasmalinauskas,項目名稱:JustMeasure,代碼行數:28,代碼來源:LoadMaps.cs

示例7: Import

        public static async Task<SaveAllSpecies> Import()
        {
            FileOpenPicker importPicker = new FileOpenPicker();
            importPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
            importPicker.FileTypeFilter.Add(".xml");
            importPicker.CommitButtonText = "Import";
            StorageFile file = await importPicker.PickSingleFileAsync();
            if (null != file)
            {
                using (var stream = await file.OpenAsync(FileAccessMode.Read))
                {
                    using (Stream inputStream = stream.AsStreamForRead())
                    {
                        SaveAllSpecies data;
                        XmlSerializer serializer = new XmlSerializer(typeof(SaveAllSpecies));
                        using (XmlReader xmlReader = XmlReader.Create(inputStream))
                        {
                            data = (SaveAllSpecies)serializer.Deserialize(xmlReader);
                        }
                        await inputStream.FlushAsync();
                        return data;
                    }                    
                }
            }
            else
            {
                //nothing
            }

            return null;
        }
開發者ID:kbo4sho,項目名稱:Swarm,代碼行數:31,代碼來源:ImportExportHelper.cs

示例8: GetThumbnailButton_Click

        private async void GetThumbnailButton_Click(object sender, RoutedEventArgs e)
        {
            rootPage.ResetOutput(ThumbnailImage, OutputTextBlock);

            // Pick a document
            FileOpenPicker openPicker = new FileOpenPicker();
            foreach (string extension in FileExtensions.Document)
            {
                openPicker.FileTypeFilter.Add(extension);
            }

            StorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                const ThumbnailMode thumbnailMode = ThumbnailMode.DocumentsView;
                const uint size = 100;
                using (StorageItemThumbnail thumbnail = await file.GetThumbnailAsync(thumbnailMode, size))
                {
                    if (thumbnail != null)
                    {
                        MainPage.DisplayResult(ThumbnailImage, OutputTextBlock, thumbnailMode.ToString(), size, file, thumbnail, false);
                    }
                    else
                    {
                        rootPage.NotifyUser(Errors.NoIcon, NotifyType.StatusMessage);
                    }
                }
            }
            else
            {
                rootPage.NotifyUser(Errors.Cancel, NotifyType.StatusMessage);
            }

        }
開發者ID:mbin,項目名稱:Win81App,代碼行數:34,代碼來源:Scenario3.xaml.cs

示例9: GetImageFromImport

        public async static Task<PhotoPageArguements> GetImageFromImport(bool isNewDocument = true)
        {
            var picker = new FileOpenPicker();

            picker.ViewMode = PickerViewMode.Thumbnail;

            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;

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

            var file = await picker.PickSingleFileAsync();

            PhotoPageArguements arguments = null;

            if (file != null)
            {
                var temporaryFolder = ApplicationData.Current.TemporaryFolder;

                await file.CopyAsync(temporaryFolder,
                    file.Name, NameCollisionOption.ReplaceExisting);

                file = await temporaryFolder.TryGetFileAsync(file.Name);

                if (file != null)
                {
                    arguments = await ImageService.GetPhotoPageArguements(file, isNewDocument);
                }
            }

            return arguments;
        }
開發者ID:epustovit,項目名稱:Scanner,代碼行數:31,代碼來源:ImageService.cs

示例10: CompareFilesButton_Click

 /// <summary>
 /// Compares a picked file with sample.dat
 /// </summary>
 private async void CompareFilesButton_Click(object sender, RoutedEventArgs e)
 {
     rootPage.ResetScenarioOutput(OutputTextBlock);
     StorageFile file = rootPage.sampleFile;
     if (file != null)
     {
         FileOpenPicker picker = new FileOpenPicker();
         picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
         picker.FileTypeFilter.Add("*");
         StorageFile comparand = await picker.PickSingleFileAsync();
         if (comparand != null)
         {
             if (file.IsEqual(comparand))
             {
                 OutputTextBlock.Text = "Files are equal";
             }
             else
             {
                 OutputTextBlock.Text = "Files are not equal";
             }
         }
         else
         {
             OutputTextBlock.Text = "Operation cancelled";
         }
     }
     else
     {
         rootPage.NotifyUserFileNotExist();
     }
 }
開發者ID:mbin,項目名稱:Win81App,代碼行數:34,代碼來源:Scenario9.xaml.cs

示例11: Load_File

		public async static Task<SimpleCollada> Load_File()
        {
            try
            {
				SimpleCollada col_scenes = null;
				XmlSerializer sr = new XmlSerializer(typeof(SimpleCollada));
                FileOpenPicker openPicker = new FileOpenPicker();
                openPicker.ViewMode = PickerViewMode.Thumbnail;
                openPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                openPicker.FileTypeFilter.Add(".xml");
                openPicker.FileTypeFilter.Add(".dae");
                StorageFile file = await openPicker.PickSingleFileAsync();
                if (file != null)
                {
                    var stream = await file.OpenStreamForReadAsync();
                    col_scenes = (SimpleCollada)(sr.Deserialize(stream));
                }
               
				return col_scenes;
            }
            catch (Exception ex)
            {
                //Console.WriteLine(ex.ToString());
                //Console.ReadLine();
				return null;
            }			
		}
開發者ID:dolkensp,項目名稱:OTWB,代碼行數:27,代碼來源:SimpleCollada.cs

示例12: PickOpenFileAsync

		public static async Task<StorageFile> PickOpenFileAsync(string[] extensions)
		{
			StorageFile file = null;
			try
			{
				Task<StorageFile> fileTask = null;
				await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Low, delegate
				{
					var openPicker = new FileOpenPicker
					{
						ViewMode = PickerViewMode.List,
						SuggestedStartLocation = PickerLocationId.DocumentsLibrary
					};

					foreach (var ext in extensions)
					{
						openPicker.FileTypeFilter.Add(ext);
					}
					fileTask = openPicker.PickSingleFileAsync().AsTask();
				});

				file = await fileTask;
			}
			catch (Exception ex)
			{
				await Logger.AddAsync(ex.ToString(), Logger.FileErrorLogFilename);
			}
			finally
			{
				SetLastPickedOpenFile(file);
				SetLastPickedOpenFileMRU(file);
			}
			return file;
		}
開發者ID:lolluslollus,項目名稱:Utilz,代碼行數:34,代碼來源:Pickers.cs

示例13: Execute

        public async override void Execute(object parameter)
        {
            var album = parameter as AlbumItem;

            if (album == null)
            {
                var args = parameter as ItemClickEventArgs;
                if(args != null)
                album = args.ClickedItem as AlbumItem;
            }

            var openPicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary
            };
            openPicker.FileTypeFilter.Add(".jpg");
            openPicker.FileTypeFilter.Add(".jpeg");
            openPicker.FileTypeFilter.Add(".png");
            openPicker.FileTypeFilter.Add(".gif");
            // Windows Phone launches the picker, then freezes the app. We need
            // to pick it up again on OnActivated.
#if WINDOWS_PHONE_APP
            App.OpenFilePickerReason = OpenFilePickerReason.OnPickingAlbumArt;
            App.SelectedAlbumItem = album;
            openPicker.PickSingleFileAndContinue();
#else
            var file = await openPicker.PickSingleFileAsync();
            if (file == null) return;
            var byteArray = await ConvertImage.ConvertImagetoByte(file);
            await App.MusicMetaService.SaveAlbumImageAsync(album, byteArray);
            await Locator.MusicLibraryVM._albumDatabase.Update(album);
#endif
        }
開發者ID:robUx4,項目名稱:vlc-winrt,代碼行數:34,代碼來源:ChangeAlbumArtCommand.cs

示例14: Execute

        public async void Execute(object parameter)
        {
            try
            {
                App.OpenFilePickerReason = OpenFilePickerReason.OnOpeningVideo;
                var picker = new FileOpenPicker
                {
                    ViewMode = PickerViewMode.List,
                    SuggestedStartLocation = PickerLocationId.VideosLibrary
                };
                foreach (var ext in _allowedExtensions)
                    picker.FileTypeFilter.Add(ext);


#if WINDOWS_APP
                StorageFile file = null;
                file = await picker.PickSingleFileAsync();
                if (file != null)
                {
                    LogHelper.Log("Opening file: " + file.Path);
                    await Locator.MediaPlaybackViewModel.OpenFile(file);
                }
                else
                {
                    LogHelper.Log("Cancelled");
                }
                App.OpenFilePickerReason = OpenFilePickerReason.Null;
#else
            picker.PickSingleFileAndContinue();
#endif
            }
            catch { }
        }
開發者ID:robUx4,項目名稱:vlc-winrt,代碼行數:33,代碼來源:PickVideoCommand.cs

示例15: MakeParameterForOffLine

        /// <summary>
        /// MakeParameterForOffLine : Make Parameter For Reports on Device
        /// </summary>
        /// <returns>Parameter String</returns>
        public static async Task<string> MakeParameterForOffLine()
        {
            string strOzdPath = string.Empty;
            string strFinalPath = string.Empty;

            try
            {
                FileOpenPicker foPicker = new FileOpenPicker();

                foPicker.ViewMode = PickerViewMode.List;
                foPicker.SuggestedStartLocation = PickerLocationId.DocumentsLibrary;
                foPicker.FileTypeFilter.Add(".ozd");

                StorageFile sfiFile = await foPicker.PickSingleFileAsync();
                StorageFolder sfoFolder = ApplicationData.Current.LocalFolder;
                
                if (sfiFile != null)
                {
                    // await sfiFile.CopyAsync(sfoFolder, sfiFile.Name, NameCollisionOption.ReplaceExisting);
                    await sfiFile.CopyAsync(sfoFolder, "insert.ozd", NameCollisionOption.ReplaceExisting);

                    //strOzdPath = ApplicationData.Current.LocalFolder.Path + "\\" + sfiFile.Name;
                    strOzdPath = ApplicationData.Current.LocalFolder.Path + "\\insert.ozd";
                    StorageFile sfoTmpFile = await StorageFile.GetFileFromPathAsync(strOzdPath);
                    strFinalPath = "connection.openfile=" + strOzdPath;
                }                
            }
            catch (Exception ex)
            {
                strFinalPath = "";
            }

            return strFinalPath;
        }
開發者ID:paraneye,項目名稱:WinApp,代碼行數:38,代碼來源:ReportUtil.cs


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