systems_ax
asked on
Error copying file or folder in C# - Try/catch statement
I have implemented a try/catch block with C#:
this is what I have -
1) have 2 textboxes and 3 buttons on my form
2) button 1 populates a file name into textbox 1
3) button 2 populates a directory/folder name into textbox 2
4) when both textboxes are filled, button 3 is pressed and the code works great
5) then what I do is I clear the path from textbox1 BUT keep the path in textbox2 and then press button 3 _ I receive appropriate message which tells me that both textboxes must be filled
6) then I clear textbox 2 and fill textbox 1 only, press button 3 and see the following error AFTER which my appropriate message box comes up -any ideas I can't think of anything that could be causing this error:
error reads:
Error copying file or folder
Cannot copy "my file name here" : The source and destination file names are the same.
any help with this will be greatly appreciated.
this is what I have -
1) have 2 textboxes and 3 buttons on my form
2) button 1 populates a file name into textbox 1
3) button 2 populates a directory/folder name into textbox 2
4) when both textboxes are filled, button 3 is pressed and the code works great
5) then what I do is I clear the path from textbox1 BUT keep the path in textbox2 and then press button 3 _ I receive appropriate message which tells me that both textboxes must be filled
6) then I clear textbox 2 and fill textbox 1 only, press button 3 and see the following error AFTER which my appropriate message box comes up -any ideas I can't think of anything that could be causing this error:
error reads:
Error copying file or folder
Cannot copy "my file name here" : The source and destination file names are the same.
any help with this will be greatly appreciated.
Can you paste code here
ASKER
try
{
if (System.Diagnostics.Proces s.GetProce ssesByName ("AdobeRea der").Leng th > 0)
{
MessageBox.Show("Close program first.", MessageBoxButtons.OK, MessageBoxIcon.Information );
}
else
{
This code works great no issues here
}
}
catch
{
MessageBox.Show("enter both paths.", MessageBoxButtons.OK, MessageBoxIcon.Information );
}
{
if (System.Diagnostics.Proces
{
MessageBox.Show("Close program first.", MessageBoxButtons.OK, MessageBoxIcon.Information
}
else
{
This code works great no issues here
}
}
catch
{
MessageBox.Show("enter both paths.", MessageBoxButtons.OK, MessageBoxIcon.Information
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.