I am writing a program in C# which has to: * make the user choose a file from a 'browse-screen' for example "C:/temp/DirectoryExample/FileExample.xxx" * save the chosen file as the name of the directory it was chosen from (in this case DirectoryExample.xxx) in a location that is pre-set by the program.
i have tried using these options to accomplish this:
if (sfdGekozenBestand.ShowDialog() == DialogResult.OK)
{
tbGekozenBestand.Text = sfdGekozenBestand.FileName;
tbVeranderNaamIn.Text = f_sNieuweNaam;
File.Copy(tbVeranderNaamIn.Text, f_sNieuweNaam, true);
}
Or
if (sfdGekozenBestand.ShowDialog() == DialogResult.OK)
{
tbGekozenBestand.Text = sfdGekozenBestand.FileName;
tbVeranderNaamIn.Text = f_sNieuweNaam;
f_srStreamReader = new StreamReader(tbGekozenBestand.Text);
f_swStreamwriter = new StreamWriter(f_sNieuweNaam);
}
Here is the thing, when i debug it in Visual studio 2010. I click the save button in the SaveFileDialog, it asks me if want to overwrite the currently existing file, I click Yes. then it crashes and gives me this:
IOExeption was unhandled.
Can't get access to the file C:/temp/DirectoryExample.xxx because it is in use by another proces
the troubleshooting tips are worthless, and my google-using skills are coming in short.
Any help would be appriciated.
[EDIT]
Fixed with How to copy a file while it is being used by other process