C# removing duplicate HTML rows -
i'm generating html file using c#. using objects , properties, i'm adding rows html table . however, i'm seeing duplicate rows don't want, though column values correct. after doing googling, found few html functions people posted accomplishing this, such as:
function removeduplicaterows($table){ function getvisiblerowtext($row){ return $row.find('td:visible').text().tolowercase(); } $table.find('tr').each(function(index, row){ var $row = $(row); $row.nextall('tr').each(function(index, next){ var $next = $(next); if(getvisiblerowtext($next) == getvisiblerowtext($row)) $next.remove(); }) }); }
and
var seen = {}; $('table tr').each(function() { var txt = $(this).text(); if (seen[txt]) $(this).remove(); else seen[txt] = true; });
however, i'm not sure how utilize in c# code (possibly lack of html coding). when tried using these , wrap each line sw.writeline, text of function. question is, how can remove duplicate html table rows in code?
what have:
streamwriter sw = new streamwriter(path.combine(cdspublishroot, "generalactive.htm")); sw.writeline("<!doctype html public \"-//w3c//dtd html 4.01//en\" \" http://www.w3.org/tr/html4/strict.dtd \">"); sw.writeline("<html>"); sw.writeline("<head>"); sw.writeline("<meta http-equiv=\"expires\" content=\"0\">"); sw.writeline("<title>gpcse-cds general</title>"); sw.writeline("</head>"); sw.writeline("<body onmousemove=\"mousemove(event)\">"); sw.writeline("<script type=\"text/javascript\">"); sw.writeline("domainmenu(false,\"sds\");"); sw.writeline("dosdssubmenu(true,\"archive\");"); sw.writeline("</script>"); sw.writeline("<p class=heading2><br>active pcm general requirement specifications<br></p>"); sw.writeline("<table cellpadding=5 cellspacing=0 border=1 width=760 id=\"maindatatable\">"); sw.writeline("<tr><th style=\"width:14%\" align=left class=sdsheader>spec.</th>"); sw.writeline("<th style=\"width:64%\" align=left class=sdsheader>specification name</th>"); sw.writeline("<th style=\"width:7%\" align=left class=sdsheader>spec. ver.</th>"); sw.writeline("<th style=\"width:7%\" align=left class=sdsheader>rev. level</th>"); sw.writeline("<th style=\"width:8%\" align=left class=sdsheader>rev. date</th></tr>"); foreach (string file in genactive.distinct()) { string[] genolddirectories = file.split(path.directoryseparatorchar); string path = path.getdirectoryname(file); string[] files = directory.getfiles(path); var acro = ardapp.data.generalspecification.generalspecversion.dataload(genolddirectories[2].tostring(), convert.toint32(genolddirectories[3][0].tostring()), convert.toint32(genolddirectories[3][2].tostring() + genolddirectories[3][3].tostring())); sw.writeline("<tr><td id=\"idtdmenutitle0008\">"); sw.writeline("<div id=\"idmenutitle0008\" class=\"clsmenutitle\" onclick=\"domenu(this)\">"); sw.writeline(genolddirectories[2] + "</div>"); sw.writeline("<div id=\"idmenu0008\" class=\"clsmenu\">"); sw.writeline("<ul class=\"clsmenubullets\">"); foreach (var filename in files) { string[] filedirectory = filename.split(path.directoryseparatorchar); sw.writeline("<li class=\"clsmenuitem\"><a class=\"clsmenuitem\" href=" + striptowebfriendlyname(file) + ">" + striptowebfriendlyname(filedirectory[5]) + "</a></li>"); } sw.writeline("</ul>"); sw.writeline("</div></td>"); sw.writeline("<td class=bodytext>" + acro.acronymname + "</td>"); sw.writeline("<td class=bodytext>" + convert.toint32(genolddirectories[3][0].tostring()) + "</td>"); sw.writeline("<td class=bodytext>" + genolddirectories[3][2].tostring() + genolddirectories[3][3] + "</td>"); sw.writeline("<td class=bodytext>" + acro.revisiondate + "</td>"); sw.writeline("</tr>"); } sw.writeline("</table>"); sw.writeline("</body>"); sw.writeline("</html>"); sw.close(); }
what tried:
....
foreach (var filename in files) { string[] filedirectory = filename.split(path.directoryseparatorchar); sw.writeline("<li class=\"clsmenuitem\"><a class=\"clsmenuitem\" href=" + striptowebfriendlyname(file) + ">" + striptowebfriendlyname(filedirectory[5]) + "</a></li>"); } sw.writeline("</ul>"); sw.writeline("</div></td>"); sw.writeline("<td class=bodytext>" + acro.acronymname + "</td>"); sw.writeline("<td class=bodytext>" + convert.toint32(genolddirectories[3][0].tostring()) + "</td>"); sw.writeline("<td class=bodytext>" + genolddirectories[3][2].tostring() + genolddirectories[3][3] + "</td>"); sw.writeline("<td class=bodytext>" + acro.revisiondate + "</td>"); sw.writeline("</tr>"); } sw.writeline("var seen = {};"); sw.writeline("$('table tr').each(function() {"); sw.writeline("var txt = $(this).text();"); sw.writeline("if (seen[txt])"); sw.writeline(" $(this).remove();"); sw.writeline("else"); sw.writeline("seen[txt] = true;"); sw.writeline("});");
looks reading in file info , want display distinct files in html display?
if still c# question, consider reading in file info (full file path info) list<string>
, use linq "distinct" non-duplicated items , output in html needed.
Comments
Post a Comment