How to move file to a new location and rename in C#

1 Answer

0 votes
using System;
using System.IO;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            string file = @"d:\data.txt";

            try
            {
                File.Move(file, @"d:\development - tools\data.bak"); // move and reanme

                Console.WriteLine("Move successes");
                
            }
            catch (IOException ioex)
            {
                Console.WriteLine(ioex.Message);
            }
        }
    }
}

/*
run:
   
Move successes

*/


answered Mar 17, 2015 by avibootz

Related questions

1 answer 129 views
129 views asked Aug 22, 2023 by avibootz
1 answer 177 views
177 views asked Aug 26, 2015 by avibootz
4 answers 391 views
391 views asked Mar 15, 2015 by avibootz
1 answer 97 views
97 views asked Aug 12, 2023 by avibootz
3 answers 267 views
1 answer 137 views
137 views asked Sep 6, 2014 by avibootz
...