I have 2 buttons (Button1 – Browse ; Button2 – Upload) and 1 textBox
Here is the scenario. When I click on Browse, it will open a window and will browse for a specific item.
The selected item will display on textbox.
private void Browse_Click(object sender, EventArgs e)
{
btnSample.Title = "Sample File Upload";
btnSample.InitialDirectory = @"c:\";
btnSample.Filter = "TIF|*.tif|JPG|*.jpg|GIF|*.gif|PNG|*.png|BMP|*.bmp|PDF|*.pdf|XLS|*.xls|DOC|*.doc|XLSX|*.xlsx|DOCX|*.docx";
btnSample.FilterIndex = 2;
btnSample.RestoreDirectory = true;
if (btnSample.ShowDialog() == DialogResult.OK)
{
textBox1.Text = btnSample.FileName;
}
}
When I click on the Upload Button the file on the textbox will be on the created folder.
I’m done with creating the folder. but my problem is how can i insert the selected file on the folder.
private void button4_Click(object sender, EventArgs e)
{
string path = @"C:\SampleFolder\NewFolder";
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
MessageBox.Show("Successfully Created New Directory");
}
else
{
MessageBox.Show("Filename Exist");
}
}
If you want to move the file:
If you want to copy the file
easy huh?
ofcourse, you’d have to adapt the paths to your problem…