Featured post

c# - Usage of Server Side Controls in MVC Frame work -

i using asp.net 4.0 , mvc 2.0 web application. project requiremrnt have use server side control in application not possibl in noraml case. ideally want use adrotator control , datalist control. i saw few samples , references in codepleax mvc controllib howwver found less useful. can tell how utilize theese controls in asp.net application along mvc. note: please provide functionalities related adrotator , datalist controls not equivalent functionalities thanks in advace. mvc pages not use normal .net solution makes use of normal .net components impossible. a normal .net page use event driven solution call different methods service side mvc use actions , view completly different way handle things. also, mvc not use viewstate normal .net controlls require. found article discussing mixing of normal .net , mvc.

c# - compare two text files using linq? -


i have 4 text files in 1 folder , pattern.txt compare these text files..in pattern.txt have

insert update delete drop 

i need compare text file 4 text files , if these patterns matches line in text files have write lines in log file...i had read files using linq..i need compare files , write in text file line number..here code

var foldercontent = directory.getfiles(patha)                     .select(filename => file.readalltext(filename))                     .aggregate(new stringbuilder(),                     (sb, s) => sb.append(s).append(environment.newline),                     sb => sb.tostring());   var pattern =  file.readalllines(pathb).aggregate(new stringbuilder(),                     (sb, s) => sb.append(s).append(environment.newline),                     sb => sb.tostring());  using (var dest = file.appendtext(path.combine(_logfolderpath, "log.txt")))             {       //dest.writeline("lineno : " + counter.tostring() + " : " + "" + line);             } 

edit have used c# compare 2 text files need in linq

while ((line = file.readline()) != null) { if (line.indexof(line2, stringcomparison.currentcultureignorecase) != -1) { dest.writeline("lineno : " + counter.tostring() + " : " + " " + line.trimstart()); } counter++; } file.basestream.seek(0, seekorigin.begin); counter = 1;  

there might simpler solution, @ least working if want use linq:

var foldercontent = directory.getfiles(patha)                     .select(filename => new                     {                         filename = filename,                         lines = file.readalllines(filename)                     })                     .selectmany(file => file.lines.select((line, idx) => new                     {                         linenumber = idx + 1,                         text = line,                         filename = file.filename                     }));  var pattern = file.readalllines(pathb);  var result = fileline in foldercontent              pattern.any(p => fileline.text.indexof(p, stringcomparison.currentcultureignorecase) != -1)              select fileline;  foreach (var match in result) {     system.diagnostics.debug.writeline("file: {0} lineno: {1}: text: {2}", match.filename, match.linenumber, match.text); } 

or if want, can combine 1 linq query (but thats not readable think):

var result = fileline in (directory.getfiles(patha)                     .select(filename => new                     {                         filename = filename,                         lines = file.readalllines(filename)                     })                     .selectmany(file => file.lines.select((line, idx) => new                     {                         linenumber = idx + 1,                         text = line,                         filename = file.filename                     })))                 file.readalllines(pathb).any(p => fileline.text.indexof(p, stringcomparison.currentcultureignorecase) != -1)                 select fileline; 

Comments

Popular posts from this blog

c# - Usage of Server Side Controls in MVC Frame work -

cocoa - Nesting arrays into NSDictionary object (Objective-C) -

ios - Very simple iPhone App crashes on UILabel settext -