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 130 views
130 views asked Aug 22, 2023 by avibootz
1 answer 178 views
178 views asked Aug 26, 2015 by avibootz
4 answers 391 views
391 views asked Mar 15, 2015 by avibootz
1 answer 98 views
98 views asked Aug 12, 2023 by avibootz
3 answers 268 views
1 answer 138 views
138 views asked Sep 6, 2014 by avibootz
...