生成静态进度条
1.bar.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>进度条</title>
<script language="javascript" type="text/javascript">
function $(obj){
return document.getElementById(obj);
}
//i为当前执行到的记录,count为总数
//比如总共需要生成的静态数为100,那么现在执行到5%,那么进度条块进到5%的地方
function loadBar(i,count){
//var a = parseFloat(i*100/count);
var a = parseInt(i*100/count);
$("bar").style.width = a + "%";
if($("bar").style.width == "100%"){
$("bar").innerHTML = "完成";
}else{
$("bar").innerHTML = a + "%";
}
}
</script>
<style type="text/css">
body{
text-align:center;
font-size:12px;
}
.graph{
width:450px;
border:1px solid #F8B3D0;
height:25px;
margin:0 auto;
}
#bar{
display:block;
background:#FFE7F4;
float:left;
height:100%;
text-align:center;
}
</style>
</head>
<body>
<form id="form1" runat="server">
<div>
<div class="graph">
<strong id="bar" style="width:1%;"></strong>
</div>
</div>
</form>
</body>
</html>
2.
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.IO;
using System.Threading;
using System.Net;
namespace DtCms.Web
{
public partial class progressbar : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
public string ip="";
protected void btnOk_Click(object sender, EventArgs e)
{
ip = lbip.Text;
string sql = "select id from dt_article ";
DataSet ds = DtCms.DBUtility.DbHelperOleDb.Query(sql);
int count = ds.Tables[0].Rows.Count;
for (int i = 0; i < count; i++)
{
if (i == 0)
{
string strFileName = filestr(Server.MapPath("~/bar.html"));
Response.Write(strFileName);
}
string id=ds.Tables[0].Rows[i]["id"].ToString();
string path = ip + "show.aspx?id="+id;
get_html(path,Server.MapPath("~/article/show_"+id+".html"));
Response.Write(path);
Response.Write("<script>loadBar(" + (i + 1) + ","+count+");</script>");
Thread.Sleep(1000);
}
}
public string filestr(string path)
{
FileStream fs = new FileStream(path,FileMode.Open);
StreamReader sr = new StreamReader(fs);
string s = sr.ReadToEnd();
sr.Dispose();
return s;
}
public void get_html(string url, string path)
{
HttpWebRequest hwr = HttpWebRequest.Create(url) as HttpWebRequest;
HttpWebResponse resp = hwr.GetResponse() as HttpWebResponse;
Stream strea = resp.GetResponseStream();
StreamReader sr = new StreamReader(strea);
string s = sr.ReadToEnd();
sr.Dispose();
FileStream fs = new FileStream(path,FileMode.Create);
StreamWriter sw = new StreamWriter(fs);
sw.Flush();
sw.Write(s);
sw.Dispose();
fs.Dispose();
}
}
}