-2

I am using Visual Studios where the below shown code is set. After you've entered the two paths, a message will come up stating the report will now produce, and the rest of the script (not shown below) will run and produce the Workbook. However, if a folder path is entered that is invalid, Visual Studios says as much in that "Does not exist". What I want to happen is IF the specified path exists, for the message to pop up saying it'll now produce, as it does now, but also as part of the Console App, for it to display something like "Path Invalid, please try again"

Console.Write("Please enter the source path for the Checks Workbook, including the name of the file (Not including the file extension): ");
string checksPath;
checksPath = Console.ReadLine()+".xlsx";

Console.Write("Please enter the folder location you wish your report to go to (Not including the file extension): ");
string reportDest;
reportDest = Console.ReadLine()+".xlsx";

Console.WriteLine("Your report will now produce");
Alexander Freyr
  • 569
  • 1
  • 6
  • 19
  • Possible duplicate of [How to find out if a file exists in C# / .NET?](https://stackoverflow.com/questions/38960/how-to-find-out-if-a-file-exists-in-c-sharp-net) – ardila Jan 21 '19 at 16:41

2 Answers2

1

you can check if file exists using System.IO.File.Exists("path")

Sergey Anisimov
  • 885
  • 8
  • 22
0

This seems to work:

                Console.Write("Please enter the folder location you wish your report to go to (Not including the file extension): ");
            string reportDest;
            reportDest = Console.ReadLine() + ".xlsx";
            Console.WriteLine(File.Exists(reportDest) ? "Your report will now produce" : "Path does not exist - please try again");