0

I am getting an error as shown in the title. I have no idea why im getting this or as to how im supposed to fix this. Visual Studio is giving me the error shown in the title on this line: var f = System.IO.File.OpenRead(fil1);

class Program {
    static void Main(string[] args) {

        Stopwatch sw = Stopwatch.StartNew();

        string fil1 = "C:\Users\mariu\Desktop\Jobboppgave\CaseConsoleApp\Prisfile.txt";

        ***var f = System.IO.File.OpenRead(fil1);***
        int length = (int)(new System.IO.FileInfo(fil1).Length);
0

1 Answer 1

14

Your path is incorrect because you didn't escape \ in it. The fastest way to do it is using @:

string fil1 = @"C:\Users\mariu\Desktop\Jobboppgave\CaseConsoleApp\Prisfile.txt";

Rebuild your project and problem will be resolved.

Sign up to request clarification or add additional context in comments.

1 Comment

Just to show the alternative, you can also write: string fil1 = "C:\\Users\\mariu\\Desktop\\Jobboppgave\\CaseConsoleApp\\Prisfile.txt";

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.