Click here to Skip to main content
15,892,480 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have the following code where I am having error in File.ReadLines in .net framework 3.5.

I am not able to use File.readAlllines as after giving this the error comes in File.WriteAlllines method

Please suggest


C#
string Activestorelist = @"C:\Activestores_default.txt";
var file1 = File.ReadLines(Activestorelist);
var file2 = File.ReadAllLines(savePath);
var onlyInFileA = file1.Except(file2);
File.WriteAllLines(savePath, onlyInFileA);
Posted
Updated 15-Feb-14 12:26pm
v2
Comments
Homero Rivera 15-Feb-14 18:36pm    
Paste all exception info available.
DEbopm 15-Feb-14 18:56pm    
var file1=File.Readlines(Activestorelist),

File.Readlines is not supported in 3.5 . How to use it here ???

1 solution

In good ol' 3.5 you can only use Read, ReadLine or WriteLine

C#
using System.IO;

...

StreamReader file = new StreamReader(@"C:\Activestores_default.txt");


string line;

while((line = file.ReadLine()) != null)
{
   // your code here...
}


You also need to use StreamReader from System.IO library.





Source
http://msdn.microsoft.com/en-us/library/aa287535(v=vs.71).aspx[^]
 
Share this answer
 
v3
Comments
DEbopm 15-Feb-14 20:15pm    
should I give the full code inside the while loop ..?? or how to put it here ??? please let me know

string Activestorelist = @"C:\Activestores_default.txt";
var file1 = File.ReadLines(Activestorelist);
var file2 = File.ReadAllLines(savePath);
var onlyInFileA = file1.Except(file2);
File.WriteAllLines(savePath, onlyInFileA);
Homero Rivera 15-Feb-14 20:23pm    
What are you trying to do with the lines you are reading? where are you trying to put all that text?

That way maybe I can complete this.
DEbopm 15-Feb-14 20:28pm    
I want to read first and then I want to write the contents which are in file 1 but not in file 2 . Then I will overwrite the savepath . How to do yhis using streamreader
DEbopm 15-Feb-14 21:22pm    
hi any input ?????

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900