Example #1
0
        // Open and fetch files in folders and its sub folders
        private void OpenFolder(string fileName, string filters)
        {
            Tbx_path.Text = fileName;
            if (Tbx_path.Text == "")
            {
                return;
            }

            string[] files = filters.Split('|').SelectMany(filter => Directory.GetFiles(Tbx_path.Text, filter, SearchOption.AllDirectories)).ToArray();
            foreach (var filePath in files)
            {
                var sysicon = System.Drawing.Icon.ExtractAssociatedIcon(filePath);
                var bmpSrc  = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon(sysicon.Handle, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions());
                sysicon.Dispose();
                DataGridBox file_items = new DataGridBox()
                {
                    fileitemIcon = bmpSrc, fileitemText = Path.GetFileName(filePath), fileitemPath = Path.GetFullPath(filePath)
                };
                gridFiles.Add(file_items);
            }

            Dg_files.ItemsSource   = gridFiles;
            Dg_files.SelectedIndex = 0;
            Lbl_count.Content      = gridFiles.Count;
        }
Example #2
0
        // set metadata by creating a new object and setting grid's datacontext for different file extensions
        private void Dg_files_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            Img_preview.Source   = null;
            Media_element.Source = null;

            try
            {
                DataGridBox dataGridFile = Dg_files.SelectedItem as DataGridBox;
                string      pathfile     = dataGridFile.fileitemPath;
                string      filterExtension;
                FileInfo    fileInfo = new FileInfo(pathfile);
                filterExtension = Path.GetExtension(pathfile).ToLower();

                var metaData = new MetaData()
                {
                    fileCreation = fileInfo.CreationTime, fileModified = fileInfo.LastWriteTime, fileName = Path.GetFileNameWithoutExtension(pathfile), fileLoc = fileInfo.FullName, fileLength = string.Concat((fileInfo.Length / 1024).ToString(), " KB"), fileType = filterExtension
                };
                Grid_metadata.DataContext = metaData;

                if (filterExtension == ".png" || filterExtension == ".jpg" || filterExtension == ".jpeg" || filterExtension == ".ico" || filterExtension == ".bmp" || filterExtension == ".jpe" || filterExtension == ".jfif")
                {
                    if (Img_preview.Visibility == Visibility.Collapsed)
                    {
                        Img_preview.Visibility   = Visibility.Visible;
                        Tblk_preview.Visibility  = Visibility.Collapsed;
                        Media_preview.Visibility = Visibility.Collapsed;
                    }
                    ImageSource imageSource = new BitmapImage(new Uri(pathfile));
                    Img_preview.Source = imageSource;
                    Media_element.Stop();
                }
                else if (filterExtension == ".wmv" || filterExtension == ".mp4" || filterExtension == ".avi" || filterExtension == ".mp3" || filterExtension == ".3gp" || filterExtension == ".flv" || filterExtension == ".mkv")
                {
                    if (Media_preview.Visibility == Visibility.Collapsed)
                    {
                        Img_preview.Visibility   = Visibility.Collapsed;
                        Tblk_preview.Visibility  = Visibility.Collapsed;
                        Media_preview.Visibility = Visibility.Visible;
                    }
                    Btn_play.Visibility            = Visibility.Visible;
                    Btn_pause.Visibility           = Visibility.Collapsed;
                    Media_element.ScrubbingEnabled = true;
                    Media_element.Source           = new Uri(pathfile);
                    Media_element.Position         = TimeSpan.FromSeconds(0);
                    Media_element.Pause();
                }
                else
                {
                    Media_element.Stop();
                    Img_preview.Visibility   = Visibility.Collapsed;
                    Tblk_preview.Visibility  = Visibility.Visible;
                    Media_preview.Visibility = Visibility.Collapsed;
                }
            }
            catch (Exception x)
            {
                Img_preview.Visibility   = Visibility.Collapsed;
                Tblk_preview.Visibility  = Visibility.Visible;
                Media_preview.Visibility = Visibility.Collapsed;
            }
        }