To get application path in C#/CSharp, we make use of GetExecutingAssembly() static method of Assembly class, which resides in System.Reflection namespace. Example is given below. using System; using System.Reflection; namespace Hello_World { class Program { static void Main(string args) { string path = Assembly.GetExecutingAssembly().Location; Console.WriteLine(path); } } }
To copy a file in C#/CSharp, we make use of File class and its method Copy. This class resides in System.IO namespace. Example is given below. using System; using System.IO; namespace Hello_World { class Program { static void Main(string args) { //Source of file string source = @"C:\Users\ADMIN\Desktop\folder1\file.txt"; //Destination Folder string destination = @"C:\Users\ADMIN\Desktop\folder2\"; //Destination
To delete a file in C#/CSharp, we make use of File class and its static method called Delete. It will take path of the file as parameter. Example is given below. using System; using System.IO; namespace Hello_World { class Program { static void Main(string args) { string path = @"C:\Users\ADMIN\Desktop\delete.txt"; File.Delete(path); Console.WriteLine("File Deleted!"); } }
To get file size in C#/CSharp, we make use FileInfo class which resides in System.IO namespace. Example is given below: using System; using System.IO; namespace Hello_World { class Program { static void Main(string args) { long filesize = new FileInfo("filname.txt").Length; Console.WriteLine(filesize); } } }
To get computer name in C#/CSharp, we make use of Environment class and its property MachineName. Example is given below. using System; namespace Hello_World { class Program { static void Main(string args) { Console.WriteLine(Environment.MachineName); } } }