Read from Location on Console C#

Read from location on console C#

This functionality doesn't exist. It's theoretically possible for you to override the input and output streams on the console to keep your own copy of the console buffer that you could read from, but it would be non-trivial (and probably couldn't support all of the edge cases such as an external program hooking into your console and reading/writing to it).

C# Reading and placing a character at a specific location

Yo shoul only use this sentence for reading the console input key with a true parameter on it

// Start a console read operation. Do not display the input.
ConsoleKeyInfo input = Console.ReadKey(true);

How to get execution directory of console application

Use Environment.CurrentDirectory.

Gets or sets the fully qualified path of the current working directory.

(MSDN Environment.CurrentDirectory Property)

string logsDirectory = Path.Combine(Environment.CurrentDirectory, "logs");

If your application is running in c:\Foo\Bar logsDirectory will point to c:\Foo\Bar\logs.

getting file path through console c#

You need to make sure your .txt file is in the same directory as the .exe you are running

You can make VisualStudio to copy it to your debug location with:

Click on your file in your solution explorer and set the "Copy to Output Directory" option

Solution Explorer

Accessing folder in console application

and create a folder in the project called 'Data'.

That doesn't work. Your program is running in the bin\Debug subdirectory of your project. It doesn't have a Data subdirectory. You'd have to use ..\..\Data\Positions.csv to find that file.

Well, that would solve your problem right now but it isn't going to be useful once you copy your program to another machine. There won't be a ..\..\Data directory there. Think about ways that your user is going to tell you where the .csv file is located. A GUI with OpenFileDialog is the friendly way but not very compatible with a console app. The standard way for that is to pass command line arguments. Environment.CommandLine. Not very compatible with the typical user. You'll have to weigh these options by yourself.



Related Topics



Leave a reply



Submit