Web
Site
Register
::
Login
Forums
February 06, 2012
Forums
Unanswered
Active Topics
Forums
Search
Forums
>
Programming - Dotnet / Delphi
>
.Net Framework Code Snippets
Subject: Read a text file into a string, like TStringList.LoadFromFile
Prev
Next
Add Reply
Author
Messages
Oldest First
Newest First
Don
New Member
Posts:20
01/30/2005 5:25 PM
Quote
Reply
private
string
ReadFileIntoString
(
string
afilename
)
{
try
{
using
(
Stream AStream
=
new
FileStream
(
afilename
,
FileMode
.
Open
,
FileAccess
.
Read
,
FileShare
.
Read
)
)
{
char
[
]
b
=
new
char
[
AStream
.
Length
-
AStream
.
Position
]
;
new
StreamReader
(
AStream
)
.
Read
(
b
,
0
,
b
.
Length
)
;
return
new
string
(
b
)
;
}
}
catch
(
Exception e
)
{
MessageBox
.
Show
(
'
Cannot open
'
+
afn
+
'
\nError is:\n
'
+
e
.
Message
)
;
}
}
Jon Shemitz wrote
in
b
.
p
.
d
.
nt
:
Um
,
yes
,
but
,
public
string
ReadFile
(
string
Filename
)
{
using
(
StreamReader Reader
=
new
StreamReader
(
FileName
)
)
return
Reader
.
ReadToEnd
(
)
;
}
Add Reply
FAQ
--General FAQ
Experiences
--Comments, complaints about anything
--Customer Service
Music
--New Music Notifications
--General Music
--St. Alphonzo's 2010
--St. Alphonzo's 2009
--St. Alphonzo's 2008
--St. Alphonzo's 2007
--St. Alphonzo's 2006
--St. Alphonzo's 2005
Programming - Dotnet / Delphi
--General DotNet
--.Net Framework Code Snippets
--ASP.NET Tips and Snippets
--Compact Framework
--Compact Framework Code Snippets
--Delphi
Forums
>
Programming - Dotnet / Delphi
>
.Net Framework Code Snippets
> Read a text file into a string, like TStringList.LoadFromFile
Quick Reply
Username:
Subject:
Body:
Submit
Home
Forums
Bluto Band
Music
Music Videos
Photographs
Download
Liquid Mix
ERG 40
Favorite Links
Home
|
Forums
|
Bluto Band
|
Music
|
Music Videos
|
Photographs
|
Download
|
Liquid Mix
|
ERG 40
|
Favorite Links