Inheritance: IFileOpenPicker
        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;
            }
        }
Esempio n. 2
0
        private async void UploadPic2(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

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

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                //imagePath.Text = file.Path;
                using (Windows.Storage.Streams.IRandomAccessStream fileStream =
                           await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.SetSource(fileStream);
                    uploadedImage2.Source = bitmapImage;
                    Button2.Visibility    = Visibility.Collapsed;
                    pic2 = true;

                    if (pic1 && pic2)
                    {
                        MixBtn.Visibility = Visibility.Visible;
                    }
                }
            }
        }
        async Task CopyImageToLocalFolderAsync()
        {
            if (rootPage.EnsureUnsnapped())
            {
                FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker();
                picker.ViewMode = PickerViewMode.Thumbnail;
                picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                picker.FileTypeFilter.Add(".jpg");
                picker.FileTypeFilter.Add(".jpeg");
                picker.FileTypeFilter.Add(".png");
                picker.FileTypeFilter.Add(".gif");
                picker.CommitButtonText = "Copy";
                StorageFile file = await picker.PickSingleFileAsync();

                if (file != null)
                {
                    StorageFile newFile = await Windows.Storage.ApplicationData.Current.LocalFolder.CreateFileAsync(file.Name, Windows.Storage.CreationCollisionOption.GenerateUniqueName);

                    await file.CopyAndReplaceAsync(newFile);

                    this.imageRelativePath = newFile.Path.Substring(newFile.Path.LastIndexOf("\\") + 1);
                    OutputTextBlock.Text   = "Image copied to application data local storage: " + newFile.Path;
                }
                else
                {
                    OutputTextBlock.Text = "File was not copied due to error or cancelled by user.";
                }
            }
            else
            {
                OutputTextBlock.Text = "Cannot unsnap the sample application.";
            }
        }
Esempio n. 4
0
        // open an existing zip file
        async void _btnOpen_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var picker = new Windows.Storage.Pickers.FileOpenPicker();

                picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
                picker.FileTypeFilter.Add(".zip");
                StorageFile _zipfile = await picker.PickSingleFileAsync();

                if (_zipfile != null)
                {
                    Clear();
                    progressBar.Visibility = Visibility.Visible;

                    if (_zip == null)
                    {
                        _zip = new C1ZipFile(new System.IO.MemoryStream(), true);
                    }
                    var stream = await _zipfile.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

                    _zip.Open(stream.AsStream());

                    _btnExtract.IsEnabled = true;
                    RefreshView();
                }
            }
            catch (Exception x)
            {
                System.Diagnostics.Debug.WriteLine(x.Message);
            }
            progressBar.Visibility = Visibility.Collapsed;
        }
Esempio n. 5
0
        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.";
            }
        }
        /// <summary>
        /// Handles the pick file button click event to load a video.
        /// </summary>
        private async void pickFileButton_Click(object sender, RoutedEventArgs e)
        {
            // Clear previous returned file name, if it exists, between iterations of this scenario 
            rootPage.NotifyUser("", NotifyType.StatusMessage);

            // Create and open the file picker
            FileOpenPicker openPicker = new FileOpenPicker();
            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;
            openPicker.FileTypeFilter.Add(".mp4");
            openPicker.FileTypeFilter.Add(".mkv");
            openPicker.FileTypeFilter.Add(".avi");

            StorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                rootPage.NotifyUser("Picked video: " + file.Name, NotifyType.StatusMessage);
                this.mediaElement.SetPlaybackSource(MediaSource.CreateFromStorageFile(file));
                this.mediaElement.Play();
            }
            else
            {
                rootPage.NotifyUser("Operation cancelled.", NotifyType.ErrorMessage);
            }
        }
        private async void BrowseButton_Click(object sender, RoutedEventArgs e)
        {

            //Upload picture 
            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();
            var bitmapImage = new BitmapImage();

            var stream = await file.OpenAsync(FileAccessMode.Read);
            bitmapImage.SetSource(stream);
           
            if (file != null)
            {
                FacePhoto.Source = bitmapImage;                
                scale = FacePhoto.Width / bitmapImage.PixelWidth;
            }
            else
            {
                Debug.WriteLine("Operation cancelled.");
            }

            // Remove any existing rectangles from previous events 
            FacesCanvas.Children.Clear();

            //DetectFaces
            var s = await file.OpenAsync(FileAccessMode.Read);
            List<MyFaceModel> faces = await DetectFaces(s.AsStream());
            DrawFaces(faces);
        }
Esempio n. 8
0
        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);
            }

        }
        private async void AddNewSongButton_Click(object sender, RoutedEventArgs e)
        {
            SwitchToContentView(ContentView.AddNewSong);
            //Instantiates File Open picker and opens the dialogue
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.MusicLibrary;

            //Filters the type of files acceptable to connect
            picker.FileTypeFilter.Add(".mp3");
            picker.FileTypeFilter.Add(".m4a");

            //Allows user to select the song
            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                // Application now has read/write access to the picked file
                SongPath_UserInput.Text = file.Path;
            }
            else
            {
                //this.textBlock.Text = "Operation cancelled.";
            }
        }
Esempio n. 10
0
        async private void SongName_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.MusicLibrary;
            picker.FileTypeFilter.Add(".mp3");
            //string path = $"C:\\Repos\\UWPMusicPlayerApp\\MyMusicPlayer\\MyMusicPlayer\\Assets\\Music\\Rock";
            string        root       = Windows.ApplicationModel.Package.Current.InstalledLocation.Path;
            StorageFolder destFolder = await StorageFolder.GetFolderFromPathAsync(root);

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                // Application now has read/write access to the picked file
                this.txtSongName.Text = file.Name;
                //   IStorageFolder folder = IStorageFolder($"/Assets/Music/{drop_category.Text}/");
                //          await file.CopyAsync(destFolder);
            }
            else
            {
                this.txtSongName.Text = "Operation cancelled.";
            }
        }
        }//Player 2 class

        /// <summary>
        /// Select_Song_Click allows user to select a song using filepicker.
        /// Filepath begins at MusicLibrary
        /// Songs are sent to MediaPlayerElement.Source
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private async void Select_Song_Click(object sender, RoutedEventArgs e)
        {
            var filePicker = new Windows.Storage.Pickers.FileOpenPicker();

            //make a collection of all Song types you want to support (for testing we are adding just 3).
            string[] fileTypes = new string[] { ".mp3" };

            //Add your fileTypes to the FileTypeFilter list of filePicker.
            foreach (string fileType in fileTypes)
            {
                filePicker.FileTypeFilter.Add(fileType);
            }

            //Set picker start location to the Music library
            filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;

            //Retrieve file from picker
            StorageFile file = await filePicker.PickSingleFileAsync();

            if (!(file is null))
            {
                _mediaSource = MediaSource.CreateFromStorageFile(file);
                System.Diagnostics.Debug.WriteLine("_mediaSource : {0} ", _mediaSource.ToString());
                _mediaPlayer.Source = _mediaSource; //what is this and what are the source requirements to get it to work?
                                                    //Can you use a URI? used a hyperlink button tag.
            }
        }
Esempio n. 12
0
        async private System.Threading.Tasks.Task SetLocalMedia()
        {
            var openPicker = new Windows.Storage.Pickers.FileOpenPicker();

            openPicker.FileTypeFilter.Add(".wmv");
            openPicker.FileTypeFilter.Add(".mp4");
            openPicker.FileTypeFilter.Add(".wma");
            openPicker.FileTypeFilter.Add(".mp3");


            var file = await openPicker.PickMultipleFilesAsync();

            // mediaPlayer is a MediaPlayerElement defined in XAML
            if (file != null)
            {
                bool first = false;
                foreach (var f in file)
                {
                    if (!first)
                    {
                        VideoFileInfoList.Add(new VideoFileInfoData(f.Name, f.Path));;


                        mediaPlayer.Source = MediaSource.CreateFromStorageFile(f);

                        mediaPlayer.MediaPlayer.Play();

                        first = true;
                    }
                }
            }
        }
Esempio n. 13
0
        private async void SelectPicture(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

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

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                BitmapImage bitmapImage = new BitmapImage();
                bitmapImage.DecodePixelWidth  = 350;
                bitmapImage.DecodePixelHeight = 180;
                await bitmapImage.SetSourceAsync(fileStream);

                background.Source = bitmapImage;
            }
        }
Esempio n. 14
0
        async private void AddSong_Click(object sender, RoutedEventArgs e)
        {
            var openPicker = new Windows.Storage.Pickers.FileOpenPicker();

            openPicker.FileTypeFilter.Add(".wmv");
            openPicker.FileTypeFilter.Add(".mp4");
            openPicker.FileTypeFilter.Add(".wma");
            openPicker.FileTypeFilter.Add(".mp3");

            StorageFile file = await openPicker.PickSingleFileAsync();

            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.Desktop;


            // video1 is a MediaElement defined in XAML
            if (null != file)
            {
                var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

                playlist[i] = file;
                int b = i + 1;
                PlaylistSongs.Text += "\n" + b.ToString() + ") " + playlist[i].DisplayName;
                Songinfo.Text       = file.DisplayName;
                // mediaControl is a MediaElement defined in XAML
                Video1.SetSource(stream, file.ContentType);
                i++;
            }
        }
Esempio n. 15
0
        public async Task LoadFromFileAsync()
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            picker.FileTypeFilter.Add(".json");

            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                // Application now has read/write access to the picked file
                string text = await Windows.Storage.FileIO.ReadTextAsync(file);

                Project project = Newtonsoft.Json.JsonConvert.DeserializeObject <Project>(text, new Newtonsoft.Json.JsonSerializerSettings
                {
                    TypeNameHandling  = Newtonsoft.Json.TypeNameHandling.Auto,
                    NullValueHandling = Newtonsoft.Json.NullValueHandling.Ignore,
                });

                Project = project;
            }
            else
            {
                // Operation cancelled.
            }
        }
        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.";
            }
        }
        private async void SetImageButton_Click(object sender, RoutedEventArgs e)
        {

            FileOpenPicker imagePicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.PicturesLibrary,
                FileTypeFilter = { ".jpg", ".jpeg", ".png", ".bmp" }
            };

            StorageFile imageFile = await imagePicker.PickSingleFileAsync();
            if (imageFile != null)
            {
                // SetAccountPictureAsync() accepts 3 storageFile objects for setting the small image, large image, and video.
                // More than one type can be set in the same call, but a small image must be accompanied by a large image and/or video.
                // If only a large image is passed, the small image will be autogenerated.
                // If only a video is passed, the large image and small will be autogenerated.
                // Videos must be convertable to mp4, <=5MB, and height and width >= 448 pixels.

                // Setting the Account Picture will fail if user disallows it in PC Settings.
                SetAccountPictureResult result = await UserInformation.SetAccountPicturesAsync(null, imageFile, null);
                if (result == SetAccountPictureResult.Success)
                {
                    rootPage.NotifyUser("Account picture was successfully changed.", NotifyType.StatusMessage);
                }
                else
                {
                    rootPage.NotifyUser("Account picture could not be changed.", NotifyType.StatusMessage);
                    AccountPictureImage.Visibility = Visibility.Collapsed;
                }
            }
        }
Esempio n. 18
0
        private async void  Button_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary;
            picker.FileTypeFilter.Add(".mp4");
            pickedFile = await picker.PickSingleFileAsync();

            var storageItemAccessList = Windows.Storage.AccessCache.StorageApplicationPermissions.FutureAccessList;

            storageItemAccessList.Add(pickedFile);

            var clip = await MediaClip.CreateFromFileAsync(pickedFile);

            if (pickedFile == null)
            {
                return;
            }


            else
            {
                composition = new MediaComposition();
                composition.Clips.Add(clip);
                mediaElement1.Position = TimeSpan.Zero;
                mediaStreamSource      = composition.GeneratePreviewMediaStreamSource(500, 200);
                mediaElement1.SetMediaStreamSource(mediaStreamSource);
                import_btn.IsEnabled = false;
            }
        }
Esempio n. 19
0
        private async void SelectPictureButton_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation =
                Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");
            Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // Set the image source to the selected bitmap.
                    Windows.UI.Xaml.Media.Imaging.BitmapImage bitmapImage =
                        new Windows.UI.Xaml.Media.Imaging.BitmapImage();

                    bitmapImage.SetSource(fileStream);
                    Background.Source = bitmapImage;
                }
            }
            else
            {
                this.textBlock.Text = "Operation cancelled.";
            }
        }
Esempio n. 20
0
        private async void OpenShitBtn_Click(object sender, RoutedEventArgs e)
        {
            //выбор файла
            Windows.Storage.Pickers.FileOpenPicker open =
                new Windows.Storage.Pickers.FileOpenPicker();
            open.SuggestedStartLocation =
                Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            open.FileTypeFilter.Add(".rtf");

            // собсно открытие файла
            Windows.Storage.StorageFile file = await open.PickSingleFileAsync();

            if (file != null)//не даст словить NRE и похожую дичь
            {
                using (Windows.Storage.Streams.IRandomAccessStream randAccStream =
                           await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // грузит содержимое файла в нашу коробычку
                    ShitEditor.Document.LoadFromStream(Windows.UI.Text.TextSetOptions.FormatRtf, randAccStream);
                }
            }
            else //если дичь таки произошла
            {
                Windows.UI.Popups.MessageDialog errorBox =
                    new Windows.UI.Popups.MessageDialog("Начальника, всё сломався!");
                await errorBox.ShowAsync();
            }
        }
Esempio n. 21
0
        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 });
                }
            }
        }
Esempio n. 22
0
        public async System.Threading.Tasks.Task AddMedia(ListView listView, MediaPlayerElement mediaPlayerElement)
        {
            var filePicker = new Windows.Storage.Pickers.FileOpenPicker();

            string[] fileTypes = new string[] { ".wmv", ".mp3", ".mp4", ".wma" };
            foreach (string fileType in fileTypes)
            {
                filePicker.FileTypeFilter.Add(fileType);
            }

            filePicker.SuggestedStartLocation = PickerLocationId.MusicLibrary;

            MediaPlaybackList _mediaPlaybackList = new MediaPlaybackList();

            var pickedFiles = await filePicker.PickMultipleFilesAsync();

            foreach (var file in pickedFiles)
            {
                var mediaPlaybackItem = new MediaPlaybackItem(MediaSource.CreateFromStorageFile(file));
                _mediaPlaybackList.Items.Add(mediaPlaybackItem);
                listView.Items.Add(file.DisplayName);
            }
            _mediaPlaybackList.AutoRepeatEnabled = true;
            mediaPlayerElement.Source            = _mediaPlaybackList;
        }
Esempio n. 23
0
        /// <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;
                }
            }
        }
        public async Task <Stream> GetStreamAsync()
        {
            ReleaseUnmanagedResources();
            StorageFile file;

            try {
                StorageFolder LocalFolder = ApplicationData.Current.LocalFolder;
                file = await LocalFolder.GetFileAsync("xamarin.appsettings.json");
            }
            catch {
                var picker = new Windows.Storage.Pickers.FileOpenPicker();
                picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.List;
                picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.ComputerFolder;
                picker.FileTypeFilter.Add(".json");

                file = await picker.PickSingleFileAsync();

                await file.CopyAsync(ApplicationData.Current.LocalFolder, "xamarin.appsettings.json", NameCollisionOption.ReplaceExisting);
            }
            _inputStream = await file.OpenReadAsync();

            _readingStream = _inputStream.AsStreamForRead();

            return(_readingStream);
        }
Esempio n. 25
0
      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.";
        }
      }
Esempio n. 26
0
        private async void dugmeUC_Click(object sender, RoutedEventArgs e)
        {
            //byte[] uploadSlika = null;
            FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".jpg");
            picker.FileTypeFilter.Add(".jpeg");
            picker.FileTypeFilter.Add(".png");
            StorageFile file = await picker.PickSingleFileAsync();

            if (file != null)
            {
                BitmapImage bitmapImage = new BitmapImage();
                using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // Set the image source to the selected bitmap
                    //uploadSlika = (await Windows.Storage.FileIO.ReadBufferAsync(file)).ToArray();
                    //AdministratorViewModel.NoviKandidat.Slika = uploadSlika;
                    //BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.DecodePixelWidth = 600; //match the target Image.Width, not shown
                    await bitmapImage.SetSourceAsync(fileStream);

                    slikaUC.Source = bitmapImage;
                    image          = slikaUC;
                }
                //uploadSlika =await spasi(bitmapImage);
            }
        }
        private async void open_btn_Click(object sender, RoutedEventArgs e)
        {
            // Open a text file.
            Windows.Storage.Pickers.FileOpenPicker open = new Windows.Storage.Pickers.FileOpenPicker();
            open.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.DocumentsLibrary;
            open.FileTypeFilter.Add(".rtf");

            Windows.Storage.StorageFile file = await open.PickSingleFileAsync();

            if (file != null)
            {
                try
                {
                    Windows.Storage.Streams.IRandomAccessStream randAccStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                    // Load the file into the Document property of the RichEditBox.
                    editBox.Document.LoadFromStream(Windows.UI.Text.TextSetOptions.FormatRtf, randAccStream);
                }
                catch (Exception)
                {
                    ContentDialog errorDialog = new ContentDialog()
                    {
                        Title             = "File open error",
                        Content           = "Sorry, I couldn't open the file.",
                        PrimaryButtonText = "Ok"
                    };

                    await errorDialog.ShowAsync();
                }
            }
        }
Esempio n. 28
0
        //从文件加载组合
        //可以从文件中反序列化媒体组合, 以允许用户查看和修改组合。选择一个组合文件, 然后调用 MediaComposition 方法 LoadAsync 以加载该组合。
        private async Task OpenComposition()
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary;
            picker.FileTypeFilter.Add(".cmp");

            StorageFile compositionFile = await picker.PickSingleFileAsync();

            if (compositionFile == null)
            {
                //w文件选择失败
            }
            else
            {
                App.Model.MediaComposition = await MediaComposition.LoadAsync(compositionFile);

                if (App.Model.MediaComposition != null)
                {
                }
                else
                {
                    //无法打开组合
                }
            }
        }
        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
                    }
                }
            }
        }
Esempio n. 30
0
        private async void button1_Click(object sender, RoutedEventArgs e)
        {
            //await appFolder.CreateFolderAsync("extractFolder",CreationCollisionOption.OpenIfExists);
            //StorageFolder extractFolder = await appFolder.GetFolderAsync("extractFolder");
            StorageFolder webFolder = await localFolder.GetFolderAsync("web");

            Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
            //openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            //openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

            openPicker.FileTypeFilter.Clear();
            openPicker.FileTypeFilter.Add(".zip");
            StorageFile zipfile = await openPicker.PickSingleFileAsync();

            if (zipfile != null)
            {
                string zipname = zipfile.Name;
                Windows.Storage.Streams.IRandomAccessStream fileStream = await zipfile.OpenAsync(FileAccessMode.Read);

                await zipfile.CopyAsync(localFolder, zipname, NameCollisionOption.ReplaceExisting);

                //string startPath = @"ms-appdata:///local/start";
                //string zipPath = "ms-appdata:///local/matlab_update.zip";
                //await webFolder.DeleteAsync();
                //await appFolder.CreateFolderAsync("zip",CreationCollisionOption.OpenIfExists);
                ZipFile.ExtractToDirectory(zipname, @"C:\Downloads\matlab");
            }
        }
        private async void SelectPictureButton_Click(object sender, RoutedEventArgs e)
        {
            FileOpenPicker openPicker = new FileOpenPicker();  //允许用户打开和选择文件的UI
            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();  //storageFile:提供有关文件及其内容以及操作的方式
            if (file != null)
            {
                path = file.Path;
                using (IRandomAccessStream fileStream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read))
                {
                    // Set the image source to the selected bitmap 
                    BitmapImage bitmapImage = new BitmapImage();
                    bitmapImage.DecodePixelWidth = 600; //match the target Image.Width, not shown
                    await bitmapImage.SetSourceAsync(fileStream);
                    img.Source = bitmapImage;
                }
            }
            else
            {
                var i = new MessageDialog("error with picture").ShowAsync();
            }
        }
Esempio n. 32
0
        private async void toggleSwitch_Toggled(object sender, RoutedEventArgs e)
        {
            StorageFolder webFolder = await localFolder.GetFolderAsync("web");

            IStorageFile namesave = await appFolder.CreateFileAsync("namesave", CreationCollisionOption.OpenIfExists);



            if (importSwitch.IsOn == true)
            {
                Windows.Storage.Pickers.FileOpenPicker openPicker = new Windows.Storage.Pickers.FileOpenPicker();
                //openPicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
                //openPicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;

                openPicker.FileTypeFilter.Clear();
                openPicker.FileTypeFilter.Add(".html");
                StorageFile updatefile = await openPicker.PickSingleFileAsync();

                if (updatefile != null)
                {
                    string updatename = updatefile.Name;
                    Windows.Storage.Streams.IRandomAccessStream fileStream = await updatefile.OpenAsync(FileAccessMode.Read);

                    await updatefile.CopyAsync(webFolder, updatename, NameCollisionOption.ReplaceExisting);

                    //var buffer = Windows.Security.Cryptography.CryptographicBuffer.ConvertStringToBinary(
                    //updatename , Windows.Security.Cryptography.BinaryStringEncoding.Utf8);
                    //await Windows.Storage.FileIO.WriteBufferAsync(namesave , buffer);

                    await FileIO.WriteTextAsync(namesave, updatename, 0);

                    text.Text = "已更新:" + updatename;
                    Uri Uri = new Uri("ms-appx-web:///web/" + updatename);
                    updateweb.Source = Uri;
                }
                else
                {
                    string updatename = "index.html";
                    await FileIO.WriteTextAsync(namesave, updatename, 0);
                }
            }
            else
            {
                IStorageFile name = await appFolder.GetFileAsync("namesave");

                string updatename = await FileIO.ReadTextAsync(name);

                //await localFolder.CreateFolderAsync("web", CreationCollisionOption.GenerateUniqueName);
                StorageFile restorefile = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///originweb/" + updatename));

                //string restorename = restorefile.Name;
                await restorefile.CopyAsync(webFolder, updatename, NameCollisionOption.ReplaceExisting);

                Uri Uri = new Uri("ms-appx-web:///web/" + updatename);
                updateweb.Source = Uri;
                await namesave.DeleteAsync();

                text.Text = "已还原:" + updatename;
            }
        }
 /// <summary>
 /// Opens a Adobe Color Swatch file, and reads its content.
 /// </summary>
 private async void Open_Executed()
 {
     var openPicker = new FileOpenPicker();
     openPicker.SuggestedStartLocation = PickerLocationId.Desktop;
     openPicker.FileTypeFilter.Add(".aco");
     StorageFile file = await openPicker.PickSingleFileAsync();
     if (null != file)
     {
         try
         {
             // User picked a file. 
             var stream = await file.OpenStreamForReadAsync();
             var reader = new AcoConverter();
             var swatchColors = reader.ReadPhotoShopSwatchFile(stream);
             Palette.Clear();
             foreach (var color in swatchColors)
             {
                 var pc = new NamedColor(color.Red, color.Green, color.Blue, color.Name);
                 Palette.Add(pc);
             }
         }
         catch (Exception ex)
         {
             Log.Error(ex.Message);
             Toast.ShowError("Oops, something went wrong.");
         }
     }
     else
     {
         // User cancelled.
         Toast.ShowWarning("Operation cancelled.");
     }
 }
Esempio n. 34
0
 /// <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();
     }
 }
Esempio n. 35
0
        private async Task OpenPictureLibrary()
        {
            FileOpenPicker open = new FileOpenPicker();
            open.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            open.ViewMode = PickerViewMode.Thumbnail;

            // Filter to include a sample subset of file types
            open.FileTypeFilter.Clear();
            open.FileTypeFilter.Add(".gif");
            open.FileTypeFilter.Add(".png");
            open.FileTypeFilter.Add(".jpeg");
            open.FileTypeFilter.Add(".jpg");

            // Open a stream for the selected file
            files = await open.PickMultipleFilesAsync();
            if(files.Count > 9)
            {
                await CoreApplication.MainView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () =>
                {
                    MessageDialog a = new MessageDialog("照片数量不得超过9张图片");
                    a.Commands.Add(new UICommand("OK"));
                    await a.ShowAsync();
                });
            }
            else
            {
                for (int i = 0; i < files.Count; i++)
                {
                    AddImageFileToData(files[i]);
                }
            }
          
        }
Esempio n. 36
0
        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;
        }
        async void OnFileOpenButtonClick(object sender, RoutedEventArgs args) {
            FileOpenPicker picker = new FileOpenPicker();
            picker.FileTypeFilter.Add(".txt");
            StorageFile storageFile = await picker.PickSingleFileAsync();

            // If user presses Cancel, result is null
            if (storageFile == null)
                return;

            Exception exception = null;

            try {
                using (IRandomAccessStream stream = await storageFile.OpenReadAsync()) {
                    using (DataReader dataReader = new DataReader(stream)) {
                        uint length = (uint)stream.Size;
                        await dataReader.LoadAsync(length);
                        txtbox.Text = dataReader.ReadString(length);
                    }
                }
            }
            catch (Exception exc) {
                exception = exc;
            }

            if (exception != null) {
                MessageDialog msgdlg = new MessageDialog(exception.Message, "File Read Error");
                await msgdlg.ShowAsync();
            }
        }
Esempio n. 38
0
        async void CopyImages_Click(object sender, RoutedEventArgs e)
        {
            if (rootPage.EnsureUnsnapped())
            {
                FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker();
                picker.ViewMode = PickerViewMode.Thumbnail;
                picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
                picker.FileTypeFilter.Add(".jpg");
                picker.FileTypeFilter.Add(".jpeg");
                picker.FileTypeFilter.Add(".png");
                picker.FileTypeFilter.Add(".gif");
                picker.CommitButtonText = "Copy";
                IReadOnlyList <StorageFile> files = await picker.PickMultipleFilesAsync();

                OutputTextBlock.Text = "Image(s) copied to application data local storage: \n";
                foreach (StorageFile file in files)
                {
                    StorageFile copyFile = await file.CopyAsync(Windows.Storage.ApplicationData.Current.LocalFolder, file.Name, Windows.Storage.NameCollisionOption.GenerateUniqueName);

                    OutputTextBlock.Text += copyFile.Path + "\n ";
                }
            }
            else
            {
                OutputTextBlock.Text = "Cannot unsnap the sample application.";
            }
        }
Esempio n. 39
0
        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;
        }
        async void PickFile(object sender, RoutedEventArgs e)
        {
            var currentState = Windows.UI.ViewManagement.ApplicationView.Value;

            if (currentState == Windows.UI.ViewManagement.ApplicationViewState.Snapped && !Windows.UI.ViewManagement.ApplicationView.TryUnsnap())
            {
                TranscodeError("Cannot pick files while application is in snapped view");
            }
            else
            {
                Windows.Storage.Pickers.FileOpenPicker picker = new Windows.Storage.Pickers.FileOpenPicker();
                picker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.VideosLibrary;
                picker.FileTypeFilter.Add(".wmv");
                picker.FileTypeFilter.Add(".mp4");

                Windows.Storage.StorageFile file = await picker.PickSingleFileAsync();

                if (file != null)
                {
                    Windows.Storage.Streams.IRandomAccessStream stream = await file.OpenAsync(Windows.Storage.FileAccessMode.Read);

                    _InputFile = file;
                    InputVideo.SetSource(stream, file.ContentType);
                    InputVideo.Play();

                    // Enable buttons
                    EnableButtons();
                }
            }
        }
Esempio n. 41
0
        private async void PlayMediaSource()
        {
            //<SnippetPlayMediaSource>
            //Create a new picker
            var filePicker = new Windows.Storage.Pickers.FileOpenPicker();

            //Add filetype filters.  In this case wmv and mp4.
            filePicker.FileTypeFilter.Add(".wmv");
            filePicker.FileTypeFilter.Add(".mp4");
            filePicker.FileTypeFilter.Add(".mkv");

            //Set picker start location to the video library
            filePicker.SuggestedStartLocation = PickerLocationId.VideosLibrary;

            //Retrieve file from picker
            StorageFile file = await filePicker.PickSingleFileAsync();

            if (file != null)
            {
                _mediaSource        = MediaSource.CreateFromStorageFile(file);
                _mediaPlayer        = new MediaPlayer();
                _mediaPlayer.Source = _mediaSource;
                mediaPlayerElement.SetMediaPlayer(_mediaPlayer);
            }
            //</SnippetPlayMediaSource>

            //<SnippetPlay>
            _mediaPlayer.Play();
            //</SnippetPlay>

            //<SnippetAutoPlay>
            _mediaPlayer.AutoPlay = true;
            //</SnippetAutoPlay>
        }
        public async void OnOpenDotnet()
        {
            try
            {
                var picker = new FileOpenPicker()
                {
                    SuggestedStartLocation = PickerLocationId.DocumentsLibrary
                };
                picker.FileTypeFilter.Add(".txt");

                StorageFile file = await picker.PickSingleFileAsync();
                if (file != null)
                {
                    IRandomAccessStreamWithContentType wrtStream = await file.OpenReadAsync();
                    Stream stream = wrtStream.AsStreamForRead();
                    using (var reader = new StreamReader(stream))
                    {
                        text1.Text = await reader.ReadToEndAsync();
                    }
                }
            }
            catch (Exception ex)
            {
                var dlg = new MessageDialog(ex.Message, "Error");
                await dlg.ShowAsync();
            }
        }
        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;
        }
Esempio n. 44
0
        private async void button_Click(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.FileTypeFilter.Add(".jpg");
            picker.PickSingleFileAndContinue();
        }
        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;
            }
        }
Esempio n. 46
0
        public async void UploadtoParse()
        {

            ParseClient.Initialize("oVFGM355Btjc1oETUvhz7AjvNbVJZXFD523abVig", "4FpFCQyO7YVmo2kMgrlymgDsshAvTnGAtQcy9NHl");

            var filePicker = new FileOpenPicker();
            filePicker.FileTypeFilter.Add(".png");
            var pickedfile = await filePicker.PickSingleFileAsync();
            using (var randomStream = (await pickedfile.OpenReadAsync()))
            {
                using (var stream = randomStream.AsStream())
                {
                    //byte[] data = System.Text.Encoding.UTF8.GetBytes("Working at Parse is great!");
                    ParseFile file = new ParseFile("resume1.png", stream);

                    await file.SaveAsync();

                    var jobApplication = new ParseObject("JobApplication");
                    jobApplication["applicantName"] = "jambor";
                    jobApplication["applicantResumeFile"] = file;
                    await jobApplication.SaveAsync();

                }
            }

          

        }
Esempio n. 47
0
        public async Task<string> GetPictureFromGalleryAsync()
		{
            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(".png");

            StorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                var stream = await file.OpenAsync(FileAccessMode.Read);
                BitmapImage image = new BitmapImage();
                image.SetSource(stream);

                var path = Path.Combine(StorageService.ImagePath);
                _url = String.Format("Image_{0}.{1}", Guid.NewGuid(), file.FileType);
                var folder = await StorageFolder.GetFolderFromPathAsync(path);

                //TODO rajouter le code pour le redimensionnement de l'image

                await file.CopyAsync(folder, _url);
                return string.Format("{0}\\{1}", path, _url);
            }

            return "";
		}
Esempio n. 48
0
        private async void openFileButton_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var pi = new FileOpenPicker();
                pi.SuggestedStartLocation = PickerLocationId.Downloads;
                pi.FileTypeFilter.Add(".dll");
                //{
                //    //SettingsIdentifier = "PE Viewer",
                //    SuggestedStartLocation = PickerLocationId.Downloads,
                //    ViewMode = PickerViewMode.List
                //};
                ////pi.FileTypeFilter.Add("DLL and EXE files|*.dll;*.exe");
                ////pi.FileTypeFilter.Add("All files|*.*");

                var fi = await pi.PickSingleFileAsync();

                var fiStream = await fi.OpenAsync(Windows.Storage.FileAccessMode.Read);
                var stream = fiStream.OpenRead();

                var buf = await ReadAll(stream);

                var bufStream = new MemoryStream(buf);

                var pe = new PEFile();
                pe.ReadFrom(new BinaryStreamReader(bufStream, new byte[32]));

                LayoutRoot.Children.Add(new PEFileView { DataContext = pe });
            }
            catch (Exception error)
            {
                openFileButton.Content = error;
            }
        }
 private void BtnBrowse_OnClick(object sender, RoutedEventArgs e)
 {
     var picker = new FileOpenPicker();
     picker.FileTypeFilter.Add(".gif");
     picker.ContinuationData["context"] = "addGifImage";
     picker.PickSingleFileAndContinue();
 }
Esempio n. 50
0
        private async void ReadToBytesTime_Tapped(object sender, TappedRoutedEventArgs e)
        {
            long readToBytes_Time;
            var  picker = new Windows.Storage.Pickers.FileOpenPicker
            {
                ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
                SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary
            };

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


            var file = await picker.PickSingleFileAsync();

            if (file == null)
            {
                return;
            }

            Stopwatch sw = new Stopwatch();

            sw.Start();
            byte[] result = await AedatUtilities.ReadToBytes(file);                        // All of the bytes in the AEDAT file loaded into an array

            sw.Stop();
            readToBytes_Time = sw.ElapsedMilliseconds;

            ContentDialog readTimeDialog = new ContentDialog()
            {
                Title           = "Testing",
                Content         = "Read to bytes time: " + readToBytes_Time + " ms",
                CloseButtonText = "Close"
            };
            await readTimeDialog.ShowAsync();
        }
Esempio n. 51
0
        private async void BtPickVideoClick(object sender, RoutedEventArgs e)
        {
            App app = Application.Current as App;

            if (app == null)
                return;
            FileOpenPicker openPicker = new FileOpenPicker
            {
                ViewMode = PickerViewMode.Thumbnail,
                SuggestedStartLocation = PickerLocationId.VideosLibrary
            };
            openPicker.FileTypeFilter.Add(".avi");
            openPicker.FileTypeFilter.Add(".mp4");

            StorageFile file = await openPicker.PickSingleFileAsync();
            if (file != null)
            {
                var client = new VideosServiceClient(app.EsbUsername, app.EsbPassword, app.EsbAccessKey);
                Video video = new Video { Title = file.DisplayName, Tags = file.DisplayName, Synopse = file.DisplayName };
                this.tblock_PostVideoResult.Text = await client.CreateVideoAsync(file, video);
            }
            else
            {
                this.tblock_PostVideoResult.Text = "Error reading file";
            }

        }
Esempio n. 52
0
        private async void ReadTest_Tapped(object sender, TappedRoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker
            {
                ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail,
                SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary
            };

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


            var file = await picker.PickSingleFileAsync();

            if (file == null)
            {
                return;
            }

            ContentDialog readTestDialog = new ContentDialog()
            {
                Title           = "Testing",
                Content         = file.Path,
                CloseButtonText = "Close"
            };
            await readTestDialog.ShowAsync();
        }
        //Button to add an Image to the document
        private async void  imgbtn_Click(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker open = new Windows.Storage.Pickers.FileOpenPicker();
            open.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            open.FileTypeFilter.Add(".jpg");
            open.FileTypeFilter.Add(".png");

            Windows.Storage.StorageFile file = await open.PickSingleFileAsync();

            if (file != null)
            {
                try
                {
                    using (IRandomAccessStream imagestram = await file.OpenReadAsync())
                    {
                        BitmapImage image = new BitmapImage();
                        await image.SetSourceAsync(imagestram);

                        editBox.Document.Selection.InsertImage(image.PixelWidth, image.PixelHeight, 0, Windows.UI.Text.VerticalCharacterAlignment.Baseline, "Image", imagestram);
                    }
                }
                catch (Exception)
                {
                    ContentDialog errorDialog = new ContentDialog()
                    {
                        Title             = "File open error",
                        Content           = "Sorry, I couldn't open the file.",
                        PrimaryButtonText = "Ok"
                    };

                    await errorDialog.ShowAsync();
                }
            }
        }
Esempio n. 54
0
        private async void click3(object sender, RoutedEventArgs e)
        {
            var picker = new Windows.Storage.Pickers.FileOpenPicker();

            picker.ViewMode = Windows.Storage.Pickers.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)

            {
                var stream = await file.OpenAsync(FileAccessMode.Read);

                var bitmap = new BitmapImage();
                //BitmapImage img = new BitmapImage();

                await bitmap.SetSourceAsync(stream);

                // 显示
                image.ImageSource = bitmap;
            }
        }
Esempio n. 55
0
        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;
            }
        }
        private async void seleccionarImagen(object sender, RoutedEventArgs e)
        {
            FileOpenPicker picker = new FileOpenPicker();
            picker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
            picker.FileTypeFilter.Add(".png");
            file = await picker.PickSingleFileAsync();

            BitmapImage image = new BitmapImage();
            try
            {
                using (var stream = await file.OpenAsync(FileAccessMode.Read))
                {
                    await image.SetSourceAsync(stream);
                }
                ImageBrush brush = new ImageBrush();
                brush.Stretch = Stretch.UniformToFill;
                brush.ImageSource = image;
                imagen.Fill = brush;
            }
            catch (Exception exception)
            {

            }
            
        }
Esempio n. 57
0
        async public void ChangeSource()
        {
            var openPicker = new Windows.Storage.Pickers.FileOpenPicker();

            openPicker.FileTypeFilter.Add(".wmv");
            openPicker.FileTypeFilter.Add(".mp4");
            openPicker.FileTypeFilter.Add(".wma");
            openPicker.FileTypeFilter.Add(".mp3");

            file = await openPicker.PickSingleFileAsync();

            openPicker.ViewMode = PickerViewMode.Thumbnail;
            openPicker.SuggestedStartLocation = PickerLocationId.Desktop;


            // video1 is a MediaElement defined in XAML
            if (null != file)
            {
                var stream = await file.OpenAsync(Windows.Storage.FileAccessMode.ReadWrite);

                Video1.SetSource(stream, file.ContentType);
                Songinfo.Text = file.DisplayName;
                Video1.Play();
            }
        }
        private async void Add_image(object sender, RoutedEventArgs e)
        {
            FileOpenPicker fp = new FileOpenPicker();

            // Adding filters for the file type to access.
            fp.FileTypeFilter.Add(".jpeg");
            fp.FileTypeFilter.Add(".png");
            fp.FileTypeFilter.Add(".bmp");
            fp.FileTypeFilter.Add(".jpg");

            // Using PickSingleFileAsync() will return a storage file which can be saved into an object of storage file class.

            StorageFile sf = await fp.PickSingleFileAsync();

            // Adding bitmap image object to store the stream provided by the object of StorageFile defined above.
            BitmapImage bmp = new BitmapImage();

            // Reading file as a stream and saving it in an object of IRandomAccess.
            IRandomAccessStream stream = await sf.OpenAsync(FileAccessMode.Read);

            // Adding stream as source of the bitmap image object defined above
            bmp.SetSource(stream);

            // Adding bmp as the source of the image in the XAML file of the document.
            image.Source = bmp;
        }
Esempio n. 59
0
        private async void ExecuteSelectPictureCommand()
        {
            try
            {
                Busy = true;

                
                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)
                {
                    // Copy the file into local folder
                    await file.CopyAsync(ApplicationData.Current.LocalFolder, file.Name, NameCollisionOption.ReplaceExisting);
                    // Save in the ToDoItem
                    TodoItem.ImageUri = new Uri("ms-appdata:///local/" + file.Name);
                }
            }
            finally { Busy = false; }
        }
Esempio n. 60
0
        private async void LoadButton_Click(object sender, RoutedEventArgs e)
        {
            Windows.Storage.Pickers.FileOpenPicker filepicker = new Windows.Storage.Pickers.FileOpenPicker();
            filepicker.SuggestedStartLocation = Windows.Storage.Pickers.PickerLocationId.PicturesLibrary;
            filepicker.FileTypeFilter.Add(".jpg");
            filepicker.FileTypeFilter.Add(".png");
            filepicker.FileTypeFilter.Add(".bmp");
            filepicker.ViewMode = Windows.Storage.Pickers.PickerViewMode.Thumbnail;
            Windows.Storage.StorageFile imageFile = await filepicker.PickSingleFileAsync();

            if (imageFile != null)
            {
                Windows.UI.Xaml.Media.Imaging.BitmapImage   bitmap = new Windows.UI.Xaml.Media.Imaging.BitmapImage();
                Windows.Storage.Streams.IRandomAccessStream stream = await imageFile.OpenAsync(Windows.Storage.FileAccessMode.Read);

                Image newImage = new Image();
                bitmap.SetSource(stream);
                newImage.Source = bitmap;
                //newImage.Height = 250;
                newImage.Stretch          = Stretch.UniformToFill;
                newImage.ManipulationMode = ManipulationModes.All;

                this.MyCanvas.Children.Add(newImage);
            }
        }