0
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
2
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by iphathuy
Featured Replies
  • 1

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

1

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

0

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.

0

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.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.