i am developing a web site in which on one page i list out the all files from given path, for that i used the scripting [i know its working only in IE but client dont have any problem for that] and by using script i list out the files, its type and size
in html table but now i want to save the file name from first first column in database, my databse is sql server 2008 but i dont know how to read html table and how to get each rows data one by one and i want to read only one row at a time , below is my script
code please help m
thanx in advance
<script>
var Fo =new ActiveXObject("Scripting.FileSystemObject");
var StrOut = new String();
var FileName = new String();
var Extention = new String();
AvinashPawar
Member
22 Points
62 Posts
how to read a data from html table in c#
May 07, 2012 02:09 PM|LINK
i am developing a web site in which on one page i list out the all files from given path, for that i used the scripting [i know its working only in IE but client dont have any problem for that] and by using script i list out the files, its type and size in html table but now i want to save the file name from first first column in database, my databse is sql server 2008 but i dont know how to read html table and how to get each rows data one by one and i want to read only one row at a time , below is my script code please help m
thanx in advance
<script>
var Fo =new ActiveXObject("Scripting.FileSystemObject");
var StrOut = new String();
var FileName = new String();
var Extention = new String();
function FindFile(FOo)
{
var FSo = new Enumerator(FOo.Files);
for(i=0;!FSo.atEnd();FSo.moveNext())
{
if(FileName == "*" || FSo.item().name.slice(0,FSo.item().name.lastIndexOf(".")).toLowerCase().indexOf(FileName)>-1)
if(Extention == "*" || FSo.item().name.slice(FSo.item().name.lastIndexOf(".")+1).toLowerCase().indexOf(Extention)>-1){
StrOut += "<tr "+ ((i%2)? "":"bgcolor=#DDAA55") +"><td width=50%><font class="find">" + FSo.item().name + "</font></td><td width=25%><font class="find">" + FSo.item().type + "</font></td><td width=50%><font class="find">"+ String(FSo.item().size/(1024*1024)).slice(0,3) +" MB</font></td></tr>";
i++
}
}
}
function Scan()
{
FileName = (search.value.lastIndexOf(".")>-1)? search.value.slice(0,search.value.lastIndexOf(".")):(search.value.length>0)? search.value.toLowerCase():"*"; //Get Searched File Name
Extention = (search.value.lastIndexOf(".")>-1)? search.value.slice(search.value.lastIndexOf(".")+1).toLowerCase():"*"; // Get Searched File Extention Name
if(path.value.length>0 && Fo.FolderExists(path.value)){
StrOut = "<table border=0 width=100% cellspacing=0>"
FindFile(Fo.GetFolder(path.value));
outPut.innerHTML = StrOut+"</table>";
}
else alert("Insert Correct Path Address");
}
</script>
<BODY topmargin="0" leftmargin="0">
<table border=0 width=100% cellspacing="0" style="border-collapse: collapse" cellpadding="2"><tr>
<td dir="ltr" bgcolor="#FFCC00"><b><font face="Arial" size="2">Named :
</font></b> </td>
<td dir="ltr" bgcolor="#FFCC00">
<input size=50 type=text id=search name=search class="Field"></td>
</tr><tr>
<td dir="ltr" bgcolor="#FFCC00">
<p dir="ltr"><b><font face="Arial" size="2">Path : </font></b> </td>
<td bgcolor="#FFCC00">
<input size=50 type=text value="C:\" id=path name=path class="Field" ></td>
</tr><tr>
<td bgcolor="#FFCC00"> </td>
<td bgcolor="#FFCC00">
<input type=button value=" Scan " onclick=Scan() class="Field"></td>
</tr><tr>
<td colspan=2 align=right bgcolor="#FFCC00"><font face=arial size=2><b>Search Result</b></font><hr></td>
</tr><tr>
<td colspan=2 bgcolor="#FFCC00"><div id=outPut></div></td>
</tr></table>
</BODY>
</HTML>
AZMatt
Star
10652 Points
1898 Posts
Re: how to read a data from html table in c#
May 07, 2012 02:47 PM|LINK
To access the table from your code, you need to add an ID tag and a runat="server" tag to the table.
<table id="someTable" runat="server" border=0 width=100% cellspacing="0" style="border-collapse: collapse" cellpadding="2">
However, it would be much easier for you work with if you used an <asp:Table> control instead.
See example #2: http://www.w3schools.com/aspnet/control_table.asp
Matt