I want to give an option of selecting the files from anywhere in the pc. Currently I am giving the path explicitly like this:
FileInfo existingFile = new FileInfo(@"C:\Users\User_name\Downloads\bank_statement.xlsx");
Using EPPlus to manipulate excel files. How to get files directly from the desired folder? Console application .NET Core 3.1 C#.
If it's really necessary to use .NET GUI components in the console application you should convert it to the UI application. But after that the application is become to GUI application (not console).
For example, you can convert to the WinForms application.
Open project file and add <UseWindowsForms>true</UseWindowsForms>
:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<UseWindowsForms>true</UseWindowsForms>
</PropertyGroup>
</Project>
Then:
using System;
using System.Windows.Forms;
namespace ConsoleApp
{
class Program
{
[STAThread]
static void Main(string[] args)
{
OpenFileDialog dialog = new OpenFileDialog();
if (DialogResult.OK == dialog.ShowDialog())
{
string path = dialog.FileName;
}
Console.WriteLine("Hello World!");
}
}
}