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 7911499
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T13:16:24+00:00 2026-06-03T13:16:24+00:00

I’m trying to build a copier so that you use the openFileDialog to chose

  • 0

I’m trying to build a copier so that you use the openFileDialog to chose a file and then the folderBrowserDialog to choose the location to copy it to.

The problem I’m having is that when I use File.Copy(copyFrom,copyTo) it gives me an exception that I can’t copy to a directory.

Is there anyway around this, or am I just missing something stupid and noobish. I’ve tryed useing openFD for choosing both locations and have just tried using the folderBD to see if it made a difference.

I know there should be if statements there to catch the exceptions but this is a rough draft of the code to get working 1st.

Thanks in advance for the help, code attached.

        // Declare for use in all methods
    public string copyFrom;
    public string copyTo;
    public string rootFolder = @"C:\Documents and Settings\cmolloy\My Documents";

    private void btnCopyFrom_Click(object sender, EventArgs e)
    {
        // uses a openFileDialog, openFD, to chose the file to copy
        copyFrom = "";

        openFD.InitialDirectory = rootFolder;
        openFD.FileName = "";

        openFD.ShowDialog();

        // sets copyFrom = to the file chosen from the openFD
        copyFrom = openFD.FileName;

        // shows it in a textbox
        txtCopyFrom.Text = copyFrom;
    }

    private void btnCopyTo_Click(object sender, EventArgs e)
    {
        //uses folderBrowserDialog, folderBD, to chose the folder to copy to
        copyTo = "";

        this.folderBD.RootFolder = System.Environment.SpecialFolder.MyDocuments;
        this.folderBD.ShowNewFolderButton = false;
        folderBD.ShowDialog();
        DialogResult result = this.folderBD.ShowDialog();

        // sets copyTo = to the folder chosen from folderBD
        copyTo = this.folderBD.SelectedPath;

        //shows it in a textbox.
        txtCopyTo.Text = copyTo;
    }

    private void btnCopy_Click(object sender, EventArgs e)
    {
        // copys file
        File.Copy(copyFrom, copyTo);
        MessageBox.Show("File Copied");
  • 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-03T13:16:26+00:00Added an answer on June 3, 2026 at 1:16 pm

    You have to append the file name to the directory path. Do this:

    string destinationPath = Path.Combine(copyTo, Path.GetFileName(copyFrom));
    File.Copy(copyFrom, destinationPath);
    

    (with this you’ll copy selected file to another directory with the same name of the original one and it’ll throw an exception if the same file already exist in that directory)

    Edit
    Side note: do not hard code the path in your source code, use this:

    rootFolder = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
    

    to get the path of current user’s documents folder.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
I am trying to render a haml file in a javascript response like so:
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to use string.replace('’','') to replace the dreaded weird single-quote character: ’ (aka
I'm trying to create an if statement in PHP that prevents a single post
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has

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.