Search code examples
c#console

how to get file location from user side in c# console application. I want full path from user side like "C:\Filepath"


I am using this to get file location from user side but user give the full path but I got only File name not a full path.

    using System.IO;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    namespace ExampleForChecking
    {
       internal class Program
       {
           static void Main(string[])
           {
               Console.WriteLine("Enter file name:");
               string v = Console.ReadLine();
               var applicationPath = Path.GetDirectoryName(v);
               Console.WriteLine(applicationPath);
           }
        }
   }

which are change required for my code to get the full path.


Solution

  • Console.WriteLine("Enter the file path:");
    string sourcePath = Console.ReadLine();