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#
Developer technologies | C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
{count} votes

Answer accepted by question author
  1. Jack J Jun 25,316 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' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.