Convert multiple files in at a time in c#

Kailash Sahu 141 Reputation points
2021-12-26T19:54:09.537+00:00

First Of all :- I have listbox and button , I want to Drap 4 files in listbox and convert it at a time like batch converter.

Code // FFMpegConverter converter = new FFMpegConverter();
160541-tyr.jpg

Developer technologies C#
{count} votes

Accepted answer
  1. Jack J Jun 25,296 Reputation points
    2021-12-27T09:08:26.337+00:00

    @Kailash Sahu , you could try the following code to drag files to listbox and convert it to the mp4 files.

    Code:

    public partial class Form1 : Form  
        {  
            public Form1()  
            {  
                InitializeComponent();  
                listBox1.AllowDrop=true;  
            }  
      
            private void button1_Click(object sender, EventArgs e)  
            {  
                string[] clist = listBox1.Items.OfType<string>().ToArray();  
                FFMpegConverter converter = new FFMpegConverter();  
                foreach (var item in clist)  
                {  
                    converter.ConvertMedia(item, Path.Combine("D:\\",Path.GetFileNameWithoutExtension(item)+".gif"), NReco.VideoConverter.Format.gif);  
                }  
            }  
      
            private void listBox1_DragEnter(object sender, DragEventArgs e)  
            {  
                if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;  
            }  
      
            private void listBox1_DragDrop(object sender, DragEventArgs e)  
            {  
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);  
                foreach (string file in files)  
                    listBox1.Items.Add(file);  
            }  
        }  
    

    Based on my test, it can convert gif to mp4 successfully at the same time.


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.