I'm new to c#. I'm trying to store the contents of a text file into a string. I tried the ReadAllLines method but it requires a string[]
            Asked
            
        
        
            Active
            
        
            Viewed 970 times
        
    4 Answers
3
            
            
        Use File.ReadAllText() like this.
string result = File.ReadAllText(filename);
 
    
    
        Yuval Itzchakov
        
- 146,575
- 32
- 257
- 321
 
    
    
        recursive
        
- 83,943
- 34
- 151
- 241
1
            Use the
File.ReadAllText()
You can find more information on the MSDN site
http://msdn.microsoft.com/en-us/library/system.io.file.readalltext(v=vs.110).aspx
 
    
    
        CinnamonBun
        
- 1,150
- 14
- 28
0
            
            
        You can use ReadAllText to read all the content from the text file into a single string.
 
    
    
        shree.pat18
        
- 21,449
- 3
- 43
- 63
0
            
            
        This will do what you seek:
using (StreamReader sr = new StreamReader("TextFile.txt"))
{
    String line = sr.ReadToEnd();
    Console.WriteLine(line);
}
 
    
    
        LB2
        
- 4,802
- 19
- 35
