[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2009-04-27
3
Medium Priority
?
215 Views
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.
0
Comment
Question by:systems_ax
  • 2
3 Comments
 
LVL 5

Expert Comment

by:Aanvik
ID: 24245013
Can you paste code here

0
 
LVL 1

Author Comment

by:systems_ax
ID: 24245069
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);
                           }
                       
0
 
LVL 5

Accepted Solution

by:
Aanvik earned 2000 total points
ID: 24245101
Before this try check if the text boxes are empty and if so return.


If(Text1.Text =="") 
{
  Messagebox.show("enter Text1");
  return;
}
 
If(Text2.Text =="") 
{
  Messagebox.show("enter Text2");
  return;
}
 
//Then your try block.

Open in new window

0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The viewer will learn how to implement Singleton Design Pattern in Java.
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
Suggested Courses
Course of the Month17 days, 14 hours left to enroll

831 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