Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7968039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T07:00:51+00:00 2026-06-04T07:00:51+00:00

I am making a software that will move files from the downloads folder to

  • 0

I am making a software that will move files from the downloads folder to a specific sub folder in a directory. The sub folder is selected by the user by a combobox. I keep getting this error: System.IO.IOException: Cannot create a file when that file already exists. Also, these error come up on people’s computer who install my program…exceptions and things. How do i turn it off. Also, why do i get this error? Here is my code:

        string pathUser4 = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
        string pathDownload4 = (pathUser4 + @"\Downloads\");
        string sourceFile = pathDownload4 + listBox1.Text;

        string pathdoc5 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        string pathDownload5 = (pathdoc5 + @"\iracing\setups\");
        string destinationFile = pathDownload5 + comboBox1.Text;

        File.Move(sourceFile, destinationFile);
        if (comboBox1.Text == "Select File Destination")
        {
            MessageBox.Show("Please Select A Destination Folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T07:00:53+00:00Added an answer on June 4, 2026 at 7:00 am

    Each File.Move should be wrapped in a try/catch block as you can never expect an IO operation to execute without error. It could be something as simple as the user having a file handle open, or the file existing in the destination folder, either way, you don’t want a single file to throw an exception that stops the entire operation. You will want to catch the exceptions and log them either to an error log file or to the event log, this way you can see the errors that occurred but it will not interrupt anything.

    Secondly, for any desktop application I would add global error handling to log any uncaught errors. You can do this by putting this code at the beginning of your program,

    AppDomain.CurrentDomain.UnhandledException += (a, exception) => File.AppendAllText("errorlog.txt", exception.ToString() + "\n"
    

    This will keep the user from ever seeing ugly exceptions being thrown. Also be sure you are not giving the users the .pdb files as this will cause exceptions to contain paths of the computer it was compiled on which can contain your username and other sensitive information you wouldn’t want a client to see.


    You can register the global exception handling when the main window is initialized, you want it to be the first thing you do before any thing else because again you never know when an exception will be thrown so you have to think defensively.

    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            AppDomain.CurrentDomain.UnhandledException += (a, exception) => File.AppendAllText("errorlog.txt", exception.ToString() + "\n");
            InitializeComponent();
        }
    }
    

    C# uses exceptions extensively so it will be good concept for you to study up on if you are not familiar with this type of error handling. All exceptions derive from the Exception class so when you write catch (Exception e) this will catch all exceptions (because a base reference can hold an object of a derived type), however if you know the specific exception a method will throw you can catch a more specific exception (always before the more general catch) and handle it in a specific way. In this example you may have an IOException from the File.Move() that you want to catch and handle differently.

    try 
    {
        string pathUser4 = Environment.GetFolderPath(Environment.SpecialFolder.UserProfile);
        string pathDownload4 = (pathUser4 + @"\Downloads\");
        string sourceFile = pathDownload4 + listBox1.Text;
    
        string pathdoc5 = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
        string pathDownload5 = (pathdoc5 + @"\iracing\setups\");
        string destinationFile = pathDownload5 + comboBox1.Text;
    
        File.Move(sourceFile, destinationFile);
        if (comboBox1.Text == "Select File Destination")
        {
            MessageBox.Show("Please Select A Destination Folder", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); 
        }
    }
    catch (Exception e)
    {
        File.AppendAllText("ErrorLog.txt", e.ToString() + "\n");
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am currently making a piece of software that will allow the user to
I need to create a porting software that will convert Java code to C#
I'm looking into making some software that makes the keyboard function like a piano
I'm looking into making some software that makes the keyboard function like a piano
I will be making a cross-platform, graphical mathematical modeling application, for example, a user
Does anybody know of a library or piece of software out there that will
I'm making a software that tries to restore a database to sql server, but
So I am making a piece of software in WPF, and I want to
I'm making a customer administration software. There are several JPanels with much content on
I'm currently making a front end to display license information for my companies software

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.