Link to home
Start Free TrialLog in
Avatar of systems_ax
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.
Avatar of Aanvik
Aanvik

Can you paste code here

Avatar of systems_ax

ASKER

try
            {
                if (System.Diagnostics.Process.GetProcessesByName("AdobeReader").Length > 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);
                           }
                       
ASKER CERTIFIED SOLUTION
Avatar of Aanvik
Aanvik

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial