By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,369 Members | 1,147 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,369 IT Pros & Developers. It's quick & easy.

.NET Framework 2.0 features on VS 2005.

P: n/a
I am tyring to use the .NET Framework 2.0 with Visual Studio 2005, but
I cannot get the System.IO / class method File ReadAllText feature to
work. How can I get this to work with VS 2005?

Thanks,
Paul

Jan 28 '07 #1
Share this Question
Share on Google+
7 Replies


P: n/a
Hello Paul,

What the problem is?
Have u tried MSDN sample http://msdn2.microsoft.com/en-us/library/ms143368.aspx
?

PLI am tyring to use the .NET Framework 2.0 with Visual Studio 2005,
PLbut I cannot get the System.IO / class method File ReadAllText
PLfeature to work. How can I get this to work with VS 2005?
PL>
PLThanks,
PLPaul
---
WBR, Michael Nemtsev [C# MVP] blog: http://spaces.live.com/laflour
team blog: http://devkids.blogspot.com/

"The greatest danger for most of us is not that our aim is too high and we
miss it, but that it is too low and we reach it" (c) Michelangelo
Jan 28 '07 #2

P: n/a
In VB2005:

'Read in a file and split the lines by CrLf
Dim crlfs() as String = {ControlChars.CrLf}
Dim lines() as String = _
File.ReadAllText("c:\data.txt").Split(crlfs, StringSplitOptions.None)
Dim numOfLines = lines.Length

If you want more help, you will need to tell exactly what's
not working, and post your code.

Robin S.
-----------------------------------------------
"Paul Lemelle" <Pl******@comcast.netwrote in message
news:6u********************************@4ax.com...
>I am tyring to use the .NET Framework 2.0 with Visual Studio 2005, but
I cannot get the System.IO / class method File ReadAllText feature to
work. How can I get this to work with VS 2005?

Thanks,
Paul

Jan 29 '07 #3

P: n/a
I am using C#, and here is the code:

using system;
using system.IO;

namespace FileIO

Class File
{
public static void Main ()
{
string myfile = File.ReadAllText("myfile");
// I do not get the File.ReadAllText - I only get Equals, Main,
// & ReferenceEquals after File.
Console.Writeline(myfile);
}
}

The code fills because the compiler does not know what to do with the
File.ReadAllText method.

Paul


On Sun, 28 Jan 2007 17:02:31 -0800, "RobinS" <Ro****@NoSpam.yah.none>
wrote:
>In VB2005:

'Read in a file and split the lines by CrLf
Dim crlfs() as String = {ControlChars.CrLf}
Dim lines() as String = _
File.ReadAllText("c:\data.txt").Split(crlfs, StringSplitOptions.None)
Dim numOfLines = lines.Length

If you want more help, you will need to tell exactly what's
not working, and post your code.

Robin S.
-----------------------------------------------
"Paul Lemelle" <Pl******@comcast.netwrote in message
news:6u********************************@4ax.com.. .
>>I am tyring to use the .NET Framework 2.0 with Visual Studio 2005, but
I cannot get the System.IO / class method File ReadAllText feature to
work. How can I get this to work with VS 2005?

Thanks,
Paul
Jan 29 '07 #4

P: n/a
I tried this, and it worked fine. I think your problem is your file name
"myfile". My guess is that it can not find the file. Try a file with a
path, like "C:\Test.txt".

Also be sure you have "using System.IO;" at the top of your class.

And Writeline should be WriteLine. C# is case-sensitive.

Robin S.
-------------------------------------
"Paul Lemelle" <Pl******@comcast.netwrote in message
news:0h********************************@4ax.com...
>I am using C#, and here is the code:

using system;
using system.IO;

namespace FileIO

Class File
{
public static void Main ()
{
string myfile = File.ReadAllText("myfile");
// I do not get the File.ReadAllText - I only get Equals, Main,
// & ReferenceEquals after File.
Console.Writeline(myfile);
}
}

The code fills because the compiler does not know what to do with the
File.ReadAllText method.

Paul


On Sun, 28 Jan 2007 17:02:31 -0800, "RobinS" <Ro****@NoSpam.yah.none>
wrote:
>>In VB2005:

'Read in a file and split the lines by CrLf
Dim crlfs() as String = {ControlChars.CrLf}
Dim lines() as String = _
File.ReadAllText("c:\data.txt").Split(crlfs, StringSplitOptions.None)
Dim numOfLines = lines.Length

If you want more help, you will need to tell exactly what's
not working, and post your code.

Robin S.
-----------------------------------------------
"Paul Lemelle" <Pl******@comcast.netwrote in message
news:6u********************************@4ax.com. ..
>>>I am tyring to use the .NET Framework 2.0 with Visual Studio 2005, but
I cannot get the System.IO / class method File ReadAllText feature to
work. How can I get this to work with VS 2005?

Thanks,
Paul

Jan 29 '07 #5

P: n/a
Naming you class as "File" is a bad choice.

You code will not compile, since you also used "System.IO" name space, which
has a class called "File". You need to qualify the class "File" to
distinguish which namespace it belongs to:

string myfile=System.IO.File.ReadAllText(...) //If the ReadAllText is not
from your custom class

or

string myfile=FileIO.File.ReadAllText(...) //If your "File" class
defines the method with the same name.

I strongly recommend you name your namespace/class wisely.
"Paul Lemelle" <Pl******@comcast.netwrote in message
news:0h********************************@4ax.com...
>I am using C#, and here is the code:

using system;
using system.IO;

namespace FileIO

Class File
{
public static void Main ()
{
string myfile = File.ReadAllText("myfile");
// I do not get the File.ReadAllText - I only get Equals, Main,
// & ReferenceEquals after File.
Console.Writeline(myfile);
}
}

The code fills because the compiler does not know what to do with the
File.ReadAllText method.

Paul


On Sun, 28 Jan 2007 17:02:31 -0800, "RobinS" <Ro****@NoSpam.yah.none>
wrote:
>>In VB2005:

'Read in a file and split the lines by CrLf
Dim crlfs() as String = {ControlChars.CrLf}
Dim lines() as String = _
File.ReadAllText("c:\data.txt").Split(crlfs, StringSplitOptions.None)
Dim numOfLines = lines.Length

If you want more help, you will need to tell exactly what's
not working, and post your code.

Robin S.
-----------------------------------------------
"Paul Lemelle" <Pl******@comcast.netwrote in message
news:6u********************************@4ax.com. ..
>>>I am tyring to use the .NET Framework 2.0 with Visual Studio 2005, but
I cannot get the System.IO / class method File ReadAllText feature to
work. How can I get this to work with VS 2005?

Thanks,
Paul

Jan 29 '07 #6

P: n/a
hi Norman,

That was it - thanks.

Paul
On Mon, 29 Jan 2007 07:33:27 -0700, "Norman Yuan"
<No*****@NotReal.notwrote:
>Naming you class as "File" is a bad choice.

You code will not compile, since you also used "System.IO" name space, which
has a class called "File". You need to qualify the class "File" to
distinguish which namespace it belongs to:

string myfile=System.IO.File.ReadAllText(...) //If the ReadAllText is not
from your custom class

or

string myfile=FileIO.File.ReadAllText(...) //If your "File" class
defines the method with the same name.

I strongly recommend you name your namespace/class wisely.
"Paul Lemelle" <Pl******@comcast.netwrote in message
news:0h********************************@4ax.com.. .
>>I am using C#, and here is the code:

using system;
using system.IO;

namespace FileIO

Class File
{
public static void Main ()
{
string myfile = File.ReadAllText("myfile");
// I do not get the File.ReadAllText - I only get Equals, Main,
// & ReferenceEquals after File.
Console.Writeline(myfile);
}
}

The code fills because the compiler does not know what to do with the
File.ReadAllText method.

Paul


On Sun, 28 Jan 2007 17:02:31 -0800, "RobinS" <Ro****@NoSpam.yah.none>
wrote:
>>>In VB2005:

'Read in a file and split the lines by CrLf
Dim crlfs() as String = {ControlChars.CrLf}
Dim lines() as String = _
File.ReadAllText("c:\data.txt").Split(crlfs, StringSplitOptions.None)
Dim numOfLines = lines.Length

If you want more help, you will need to tell exactly what's
not working, and post your code.

Robin S.
-----------------------------------------------
"Paul Lemelle" <Pl******@comcast.netwrote in message
news:6u********************************@4ax.com ...
I am tyring to use the .NET Framework 2.0 with Visual Studio 2005, but
I cannot get the System.IO / class method File ReadAllText feature to
work. How can I get this to work with VS 2005?

Thanks,
Paul

Jan 29 '07 #7

P: n/a
Paul Lemelle <Pl******@comcast.netwrote:
I am using C#, and here is the code:

using system;
using system.IO;

namespace FileIO

Class File
{
public static void Main ()
{
string myfile = File.ReadAllText("myfile");
// I do not get the File.ReadAllText - I only get Equals, Main,
// & ReferenceEquals after File.
Console.Writeline(myfile);
}
}
That's certainly not the code you had mostly working - it's really
helpful if you cut and paste the *actual* code in, rather than creating
a *similar* program which will fail for other reasons. Problems with
the above, *apart* from the collision of the "File" name:

1) Case of "system"
2) No braces after the namespace declaration
3) Case of class declaration
4) Case of the "l" in Writeline

In general, if you've already got a problem in your code, it makes it
hard for us to tell the problems which are *really* there compared with
typos when retyping the code unless you use cut and paste properly.

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet
If replying to the group, please do not mail me too
Jan 29 '07 #8

This discussion thread is closed

Replies have been disabled for this discussion.