?
Solved

Cannot read text file

Posted on 2003-03-17
6
Medium Priority
?
322 Views
Last Modified: 2009-07-29
When I execute my read text file program, the
following message appeared:
An execption system security execption has
occured in project.
Can anyone tell me why?

len00
0
Comment
Question by:len00
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 

Expert Comment

by:Bulls
ID: 8151955
Hi

Couold you post more info, maybe the code, but my guess is that you don't have sufficient permission.

Cheers
0
 
LVL 24

Expert Comment

by:SunBow
ID: 8154910
If you get permission, then you can move on to next error. In meantime system has labeled you as violator. Best to only access your own files, IMO.
0
 
LVL 7

Expert Comment

by:God_Ares
ID: 8158127
start over and see if you have the same problem:

THIS IS A CONSOLE APPLICATION. just make a MyFile.txt in the same path as your app and fill it with text.

using System;
using System.IO;
public class TextFromFile
{
    private const string FILE_NAME = "MyFile.txt";
    public static void Main(String[] args)
    {
        if (!File.Exists(FILE_NAME))
        {
            Console.WriteLine("{0} does not exist.", FILE_NAME);
            return;
        }
        StreamReader sr = File.OpenText(FILE_NAME);
        String input;
        while ((input=sr.ReadLine())!=null)
        {
            Console.WriteLine(input);
        }
        Console.WriteLine ("The end of the stream has been reached.");
        sr.Close();
    }
}
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

Author Comment

by:len00
ID: 8165882
Thank you for your respone, but the problem still occured.
Is it because the network drive that I'm using? I'm not allowed to used the local drive, so I'm using the network drive that is allocated to me to do all my project. If the network drive is the problem, how can I overcome the problem so that I can execute my read text file program succesfully.

For the reference, here is my program:

using System;
using System.Collections;
using System.IO;

public class Read
{
    public static void Main()
    {    
     string fileContent;
     FileStream myStream = new FileStream
        ("P:\\TestInput.txt",FileMode.Open);
     StreamReader myStreamReader = new StreamReader
        (myStream);
     fileContent = myStreamReader.ReadToEnd();
     Console.WriteLine("{0}",fileContent);
     Console.ReadLine();
    }
}

len00
0
 

Expert Comment

by:Bulls
ID: 8166042
Hi

I tried your code and it works, but what happens when you add the 3rd parameter to new FileStream.

Ex:

FileStream fs = new FileStream("P:\\TestInput.txt", FileMode.Open, FileAccess.ReadWrite);

O yea, the file does exist, right?

Cheers
0
 
LVL 14

Accepted Solution

by:
AvonWyss earned 80 total points
ID: 8167704
Its probably the network share. Note that applications which are not run from a local disk do have less proviledges than ones run from a lokal drive. You may try to use the floppy disk drive (copy your app there and try it) to see if the problem gets solved by this.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Although it is an old technology, serial ports are still being used by many hardware manufacturers. If you develop applications in C#, Microsoft .NET framework has SerialPort class to communicate with the serial ports.  I needed to…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question