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.

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();
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.