Go Back   HTMLCenter Web Development Forums > Web Design and Development > Programming and Scripting

Reply
 
LinkBack Thread Tools Rate Thread Display Modes
  #1 (permalink)  
Old 07-19-2008, 07:57 AM
Registered User
 
Join Date: Jul 2008
Posts: 1
Code for How to read file content in .Net

This is the code how to read file content through .Net.



Code:
public String ReadFileContent(FileSettings file)

{ 

FileStream fs = new FileStream(file.FilePath,FileMode.Open,FileAccess.Read);

StringBuilder output = new StringBuilder();

StreamReader r = new StreamReader(fs);

r.BaseStream.Seek(0,SeekOrigin.Begin);

String fContent="";

while (r.Peek() > -1)

{

fContent = fContent + r.ReadLine();

}

r.Close();

return fContent;

}


--------------------------------------------------------------------------------

Last edited by curtiss : 07-19-2008 at 09:20 AM.
Reply With Quote

  #2 (permalink)  
Old 07-21-2008, 10:10 AM
Deadeye's Avatar
Moderator
 
Join Date: Aug 2005
Location: San Diego, CA
Posts: 268
Send a message via MSN to Deadeye
you're way is a little long.

Code:
public static void Main()
{
   ReadFromFile("c:\\MyTextFile.txt");
}

static void ReadFromFile(string filename)
{
   StreamReader SR;
   string S;
   SR=File.OpenText(filename);
   S=SR.ReadLine();
   while(S!=null)
   {
      Console.WriteLine(S);
      S=SR.ReadLine();
   }
   SR.Close();
}
and to top it off you never use
Code:
StringBuilder output = new StringBuilder();
in your method

Wesley
__________________
Don't forget to rate me A+++++++++++++++++!!!!!111one for the service you have received.
Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP Code, Efficiency and Benchmarking curtiss Programming and Scripting 2 06-02-2008 05:42 PM
Force a menu button to read text file (not cached) Bad Inferno Programming and Scripting 1 06-21-2007 08:41 AM
Problem with writing file in perl gugabaga Programming and Scripting 1 06-27-2006 08:17 AM
Creating a file and saving it locally - PHP curtiss Programming and Scripting 6 03-25-2006 11:26 AM
Aligning? Saavan Programming and Scripting 1 12-19-2005 02:52 AM


All times are GMT -5. The time now is 11:33 PM.

 
KickApps
Clicky Web Analytics


Subscribe to our feed | add to myYahoo!

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.2.0
© 1997-2007 HTMLCenter