Reputation: 543
I have very simple program. Here I set the absolute path,but C# thinks that it's a relative path and try to load the file from project directory: C:\Users\Gleb Kozyukevich\source\repos\ChangeDir\ChageDir\bin\Debug\netcoreapp3.1\C:\test\test.txt
The path really exists.
What did I miss? I can't get understand
Upvotes: 0
Views: 270
Reputation: 2792
That is very strange. I've reproduced the code the way I think you wrote it and the result is just fine.
Here the code I wrote:
using System;
using System.IO;
namespace ReadAllLines
{
internal class Program
{
static void Main(string[] args)
{
var lines = File.ReadAllLines(@"c:\temp\test.txt");
Console.ReadKey();
}
}
}
Upvotes: 1
Reputation: 17485
There are multiple ways you try.
string sourceFilePath = @"C:\test\test.txt";
string sourceFilePath = System.IO.Path.Combine(new []{"C:","test","test.txt"});
Upvotes: 3