I'm trying to create a copy button for files with this specific function:
When I write in the textbox for example "KL5050" and then press the copy button, I want to copy the file KL5050 from a specific folder and paste it to another specific folder without asking or opening any dialog or window, just click, copy and paste.
It doesn't matter the file format, it could be TXT, doc, PDF, JPEG, etc., as long as it matches the text from the textbox to any existing file in the folder it will be copied to another folder.
Also, if the file doesn't exist from the copy folder, get a warning "file not found".
The code that I have so far has two textboxes, the first is called serieBox, that one only requires input data (if is empty opens a window) before proceeding to the next box, then the next box is named recetaBox, which is the one where I type the name of file and then clicking the button, the program will look for the file and copy it to the different folder. So far I don't know where to put the second box, recetaBox. Is not in the code yet.
private void cargarButton_Click(object sender, EventArgs e)
{
if (serieBox.Text == string.Empty)
{
SerieWin openForm = new SerieWin();
openForm.ShowDialog();
}
else
{
try
{
string dircopyFrom = @"C:\From\";
string dircopyTo = @"C:\To\";
string[] files = Directory.GetFiles(dircopyFrom);
foreach (string file1 in files)
{
string filename1 = Path.GetFileName(file1);
File.Copy(file1, dircopyTo + "\\", true);
}
}
catch (Exception ex)
{
}