A
A
Alex2018-09-22 10:55:19
.NET
Alex, 2018-09-22 10:55:19

Am I referring to the file by address correctly?

Am I accessing the file correctly?

StreamReader fr = new StreamReader("D:\\C# Projects\\ONU-Manager\\ONU-Manager\\bin\\Debug\\check.txt");

When accessing the current file, I get an error:
System.IO.DirectoryNotFoundException: Could not find part of the path "D:\C# Projects\ONU-Manager\ONU-Manager\bin\Debug\check.txt".
Screenshot with the path to the file location in Windows:
5ba5f544c67f2304164736.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
#
#, 2018-09-22
@cocaine4ik

on the screenshot, one "ONU-Manager" is separated by a hyphen, the other is separated by a space.
In addition, use the syntax that will allow you to copy the path from the explorer
StreamReader fr = new StreamReader(@"D:\C# Projects\ONU-Manager\ONU Manager\bin\ debug\check.txt");
ps use as an example for reflection

using System;
using System.IO;

namespace mypath
{
    class Program
    {
        static void Main(string[] args)
        {
            var p = Environment.CurrentDirectory;
            Console.WriteLine(p);
            Console.ReadKey();
            p += @"\..\..\App.config";
            var appcfg = File.ReadLines(p);
            foreach(var l in appcfg)
                Console.WriteLine(l);
            Console.ReadKey();
        }
    }
}

L
LiptonOlolo, 2018-09-22
@LiptonOlolo

Use the Path and AppDomain class:
Let's get the full path to the folder from which the program was launched and add our file there.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question