private async void SendFileToStorage(object sender, RoutedEventArgs e) { Flyout fly = new Flyout(); fly.PlacementTarget = sender as UIElement; fly.Placement = PlacementMode.Top; fly.Closed += (x, y) => { }; ObservableCollection<selectingfiles> oc = new ObservableCollection<selectingfiles>(); ListView a = new ListView(); a.ItemTemplate = (DataTemplate)Application.Current.Resources["DeviceTemplate"]; a.Width = 220; a.Height = 50; a.BorderBrush = new SolidColorBrush(Colors.BlueViolet); a.Background = new SolidColorBrush(Colors.Lavender); a.Foreground = new SolidColorBrush(Colors.Black); DeviceInformationCollection _device; _device = null; _device = await DeviceInformation.FindAllAsync(StorageDevice.GetDeviceSelector()); oc.Clear(); foreach (DeviceInformation dv in _device) { var dd = StorageDevice.FromId(dv.Id); selectingfiles g = new selectingfiles { DeviceInfo = dv, DeviceName = dd.DisplayName, }; oc.Add(g); } if (oc.Count > 0) { a.Height = oc.Count * 50; a.ItemsSource = oc; fly.Content = a; fly.IsOpen = true; UpdateLayout(); } else { fly.IsOpen = false; UpdateLayout(); try { await new MessageDialog("Removable Devices Not Found !!!").ShowAsync(); } catch (Exception) { } } //var removableStorages = await KnownFolders.RemovableDevices.GetFoldersAsync(); //if (removableStorages.Count > 0) //{ // // Display each storage device // foreach (StorageFolder storage in removableStorages) // { // a.Items.Add(storage.DisplayName); // } //} a.SelectionChanged += async (object se, SelectionChangedEventArgs f) => { object ff = a.SelectedItem; selectingfiles ss = ff as selectingfiles; object ls = ls1.SelectedItem; playlist pl = ls as playlist; fly.IsOpen = false; var storage = StorageDevice.FromId(ss.DeviceInfo.Id); if (ls1.SelectedItem != null) { try { progressring.IsActive = true; //await Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => // { // await // pl.MediaFile.CopyAsync(storage, pl.MediaFile.Name, // NameCollisionOption.GenerateUniqueName); // }); //progressring.IsActive = false; var s = pl.MediaFile.CopyAsync(storage, pl.MediaFile.Name, NameCollisionOption.GenerateUniqueName).GetAwaiter(); //var dresult = s.GetAwaiter(); s.OnCompleted(async() => { await new MessageDialog("File Sended Successfully").ShowAsync(); progressring.IsActive = false; }); } catch { ErrorCorrecting("027"); } } else { new MessageDialog("First Select The Media in List!!!Then Send To Removable Device"); } }; }
private async void Loadmediafromdevice(object sender, RoutedEventArgs e) { Flyout fly = new Flyout(); fly.PlacementTarget = sender as UIElement; fly.Placement = PlacementMode.Top; fly.Closed += (x, y) => { }; ObservableCollection<selectingfiles> oc = new ObservableCollection<selectingfiles>(); ListView a = new ListView(); a.ItemTemplate = (DataTemplate)Application.Current.Resources["DeviceTemplate"]; a.Width = 220; a.Height = 50; a.BorderBrush = new SolidColorBrush(Colors.BlueViolet); a.Background = new SolidColorBrush(Colors.Lavender); a.Foreground = new SolidColorBrush(Colors.Black); DeviceInformationCollection _device; _device = null; _device = await DeviceInformation.FindAllAsync(StorageDevice.GetDeviceSelector()); oc.Clear(); foreach (DeviceInformation dv in _device) { var dd = StorageDevice.FromId(dv.Id); selectingfiles g = new selectingfiles { DeviceInfo = dv, DeviceName = dd.DisplayName, }; oc.Add(g); } if (oc.Count > 0) { a.Height = oc.Count * 50; a.ItemsSource = oc; fly.Content = a; fly.IsOpen = true; UpdateLayout(); } else { fly.IsOpen = false; UpdateLayout(); try { await new MessageDialog("Removeable Devices Not Found !!!").ShowAsync(); } catch (Exception) { } } //var removableStorages = await KnownFolders.RemovableDevices.GetFoldersAsync(); //if (removableStorages.Count > 0) //{ // // Display each storage device // foreach (StorageFolder storage in removableStorages) // { // a.Items.Add(storage.DisplayName); // } //} a.SelectionChanged += async (object se, SelectionChangedEventArgs f) => { object ff = a.SelectedItem; selectingfiles ss = ff as selectingfiles; fly.IsOpen = false; var storage = StorageDevice.FromId(ss.DeviceInfo.Id); //var storageName = deviceInfoElement.Name; // Construct the query for image files var QueryOptions = new QueryOptions ( CommonFileQuery.OrderByName, new List<string> { ".3g2", ".3gp2", ".3gp", ".3gpp", ".m4a", ".m4v", ".mp4v", ".mp4", ".mov", ".m2ts", ".asf", ".wm", ".vob", ".wmv", ".wma", ".aac", ".adt", ".mp3", ".wav", ".avi", ".ac3", ".ec3" } ); var FileQuery = storage.CreateFileQueryWithOptions(QueryOptions); // Run the query for image files var Files = await FileQuery.GetFilesAsync(); file = Files; try { await pickingfiles(); } catch { ErrorCorrecting("025"); } ////if (Files.Count > 0) ////{ //// var imageFile = Files[0]; ////} }; }