How to copy images and videos file asynchronous in c# WPF? I am already using this for copying txt files and its working, but if I use it for copying images or videos, the result does not open or crash. Any Idea what could be wrong? This is my code
private async void btnUpdate_Click(object sender, RoutedEventArgs e)
{
string x2 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
DirectoryInfo dinfo = new DirectoryInfo(x2);
FileInfo[] Files = dinfo.GetFiles("*.txt");
int jml = 0;
foreach (FileInfo file in Files)
{
string fileNoExtension = file.Name.Replace(".txt", "");
string fileName2 = x2 + @"\Data\" + file.Name;
using (StreamReader SourceReader = File.OpenText(@"Data\" + file.Name))
{
using (StreamWriter DestinationWriter = File.CreateText(x2 + @"\Data\" + file.Name))
{
await CopyFilesAsync(SourceReader, DestinationWriter);
}
}
lbxHasil.Items.Add(file.Name);
jml = jml + 1;
}
MessageBox.Show("Success add " + jml.ToString() + " New Songs!!!");
btnUpdate.IsEnabled = false;
lbxAwal.Items.Clear();
}