using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace FileApp
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("***** Simple IO with the File Type ******");
            string[] myTasks = { "asdf", "qwerty", "awdx", "1234" };
            // Write out all data to file on C drive.
            File.WriteAllLines(@"C:\tasks.txt", myTasks);
            // Read it all back and print out
            foreach (string task in File.ReadAllLines(@"C:\tasks.txt"))
            {
                Console.WriteLine("TODO: {0}", task);
            }
            Console.ReadLine();
        }
    }
}

The program could not access tasks.txt, I attached a screenshot of problem.

Attachments Capture.PNG 42.62 KB

Windows Vista and Windows 7 consider the root directory of the C: drive to be a protected directory. Put the file somewhere else.

Windows Vista and Windows 7 consider the root directory of the C: drive to be a protected directory. Put the file somewhere else.

Sorry, the problem is not solved yet. I changed location of "tasks.txt" but the exception still throws.

Sorry, the problem is not solved yet. I changed location of "tasks.txt" but the exception still throws.

I solved the problem

static void Main(string[] args)
        {
            Console.WriteLine("***** Simple IO with the File Type ******");
            string[] myTasks = { "asdf", "qwerty", "awdx", "1234" };
            // Write out all data to file on C drive.
            File.WriteAllLines(@"C:\temp\tasks.txt", myTasks);
            // Read it all back and print out
            foreach (string task in File.ReadAllLines(@"C:\temp\tasks.txt"))
            {
                Console.WriteLine("TODO: {0}", task);
            }
            Console.ReadLine();
        }
This question has already been answered. Start a new discussion instead.