Error copying file or folder in C# - Try/catch statement

Posted on 2009-04-27
Last Modified: 2013-12-17
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.
Question by:systems_ax
    LVL 5

    Expert Comment

    Can you paste code here

    LVL 1

    Author Comment

                    if (System.Diagnostics.Process.GetProcessesByName("AdobeReader").Length > 0)
                        MessageBox.Show("Close program first.", MessageBoxButtons.OK, MessageBoxIcon.Information);


                        This code works great  no issues here
                      MessageBox.Show("enter both paths.", MessageBoxButtons.OK, MessageBoxIcon.Information);
    LVL 5

    Accepted Solution

    Before this try check if the text boxes are empty and if so return.

    If(Text1.Text =="") 
 "enter Text1");
    If(Text2.Text =="") 
 "enter Text2");
    //Then your try block.

    Open in new window


    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    Join & Write a Comment

    Navigation is an important part of web design from a usability perspective. But it is often a pain when it comes to a developer’s perspective. By navigation, it often means menuing. This is less theory and more practical of how to get a specific gro…
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    The viewer will learn how to implement Singleton Design Pattern in Java.
    Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

    734 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    23 Experts available now in Live!

    Get 1:1 Help Now