Friday, 11 October 2013

How to copy a file in C# .Net

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace file
{
    class Program
    {
        static void Main(string[] args)
        {
            string path = "my_text.txt";
// copy a file

            int a = 0;
            try
            {
              
                if (a == 0)
                {
                    File.Copy(path, "hell.txt" );
                    a++;
                }
            }
            catch(Exception e)
            {
                Console.WriteLine(e.Message);
           
            }
        
            if (a > 0)
            {
                Console.WriteLine("file copied");

            }
          
        }
    }
}

0 comments:

Post a Comment