Advertisement
DrAungWinHtut

Extension Dependent File Open in CS

Mar 16th, 2022
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.06 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using System.IO;
  11. using System.Diagnostics;
  12.  
  13. namespace PlayerTest
  14. {
  15.     public partial class frmPlayer : Form
  16.     {
  17.         string sPath;
  18.         public frmPlayer()
  19.         {
  20.             InitializeComponent();
  21.         }
  22.  
  23.         private void btnLoadFileList_Click(object sender, EventArgs e)
  24.         {
  25.             sPath = txtPath .Text;
  26.             if(Directory.Exists(sPath))
  27.             {
  28.                 string[] saFileList = Directory.GetFiles(sPath);
  29.                 string[] saSplitPath;
  30.                 foreach (string sFile in saFileList)
  31.                 {
  32.                     saSplitPath = sFile.Split('\\');
  33.                     int iLength = saSplitPath.Length;
  34.                     lstFileList.Items.Add(saSplitPath [iLength -1]);
  35.                 }
  36.             }
  37.             else
  38.             {
  39.                 MessageBox.Show("Invalid Path");
  40.                 txtPath .SelectAll ();
  41.                 txtPath .Focus ();
  42.             }
  43.          
  44.         }
  45.  
  46.         private void lstFileList_SelectedIndexChanged(object sender, EventArgs e)
  47.         {
  48.             string sVlcPath = @"C:\Program Files (x86)\VideoLAN\VLC\vlc.exe";
  49.             string sExcelPath = @"C:\Program Files\Microsoft Office\root\Office16\EXCEL.EXE";
  50.             string sWordPath = @"C:\Program Files\Microsoft Office\root\Office16\WINWORD.EXE";
  51.             if(lstFileList.SelectedItem != null )
  52.             {
  53.                 string sSelectedVideo = lstFileList.SelectedItem.ToString();
  54.                 string sVideoFile = sPath + "\\" + sSelectedVideo;
  55.                 string sVideoFileVlc = "\"" + sPath + "\\" + sSelectedVideo + "\"";
  56.                 //wmpPlayer .URL = sVideoFile;
  57.                 string[] sExt = sSelectedVideo.Split('.');
  58.                 if (sExt[1] == "mp4")
  59.                 {
  60.                     Process.Start(sVlcPath, sVideoFileVlc);
  61.                 }
  62.                 else if ((sExt[1] == "jpg") || (sExt[1] == "png"))
  63.                 {
  64.                     Process.Start("mspaint", sVideoFileVlc);
  65.                 }
  66.                 else if ((sExt[1] == "txt") || (sExt[1] == "py"))
  67.                 {
  68.                     Process.Start("notepad", sVideoFileVlc);
  69.                 }
  70.                 else if (sExt[1] == "xlsx")
  71.                 {
  72.                     Process.Start(sExcelPath, sVideoFileVlc);
  73.                 }
  74.                 else if (sExt[1] == "docx")
  75.                 {
  76.                     Process.Start(sWordPath, sVideoFileVlc);
  77.                 }
  78.                 else if (sExt[1] == "exe")
  79.                 {
  80.                     Process.Start(sVideoFileVlc);
  81.                 }
  82.             }
  83.            
  84.  
  85.         }
  86.  
  87.         private void btnBrowseFile_Click(object sender, EventArgs e)
  88.         {
  89.             ofdSelectFile.ShowDialog();
  90.             lstFileList .Items.Add (ofdSelectFile.FileName);
  91.         }
  92.     }
  93. }
  94.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement