DataSet ds = null;
int res = 1;
string sql = "select top(10)* from gb_NewsInfo order by ID desc";
SqlParameter[] sp = new SqlParameter[] { };
ds = Utility.SqlHelper.ExecuteDataSet(Utility.SqlHelper.appName, CommandType.Text, sql, sp);
if (ds != null && ds.Tables[0].Rows.Count > 0)
{
DataTable dt = ds.Tables[0];
for (int i = 0; i < dt.Rows.Count; i++)
{
try
{
int id = int.Parse(dt.Rows[i]["ID"].ToString());
string title = dt.Rows[i]["Title"].ToString();
string cont = dt.Rows[i]["NewsContent"].ToString();
string temCode = tmhelper.getTimeCode() + ".htm";
string Dirctory = tmhelper.getDirctoryCode();
if (!Directory.Exists(context.Server.MapPath(@"~/Static/NewsInfo/" + Dirctory)))
{
Directory.CreateDirectory(context.Server.MapPath(@"~/Static/NewsInfo/" + Dirctory));
} FileStream fs = new FileStream(context.Server.MapPath(@"~/Static/NewsInfo/htm.htm"), FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs, Encoding.UTF8); StringBuilder sb = new StringBuilder();
sb.Append(sr.ReadToEnd()); sb.Replace("$replace[title]$", title);
sb.Replace("$replace[cont]$", cont); FileStream fsw = new FileStream(context.Server.MapPath(@"~/Static/NewsInfo/" + Dirctory + "/" + temCode), FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter sw = new StreamWriter(fsw, Encoding.UTF8);
sw.Write(sb.ToString());
sw.Flush();
sw.Close(); string updateSql = "update gb_NewsInfo set StaticURL='" + Dirctory + "/" + temCode + "' where ID=" + id;
if (Utility.SqlHelper.ExecuteNonQuery(Utility.SqlHelper.appName, CommandType.Text, updateSql, sp) != 1)
{
if (File.Exists(context.Server.MapPath(@"~/Static/NewsInfo/" + Dirctory + "/" + temCode)))
{
File.Delete(context.Server.MapPath(@"~/Static/NewsInfo/" + Dirctory + "/" + temCode));
res = 2;
break;
}
res = 2;
}
}
catch { res = 0; break; }
}
} context.Response.Write(res.ToString());
context.Response.End();
{
context.Response.Buffer = true;
context.Response.ExpiresAbsolute = DateTime.Now.AddDays(-1);
context.Response.AddHeader("pragma", "no-cache");
context.Response.AddHeader("cache-control", "");
context.Response.CacheControl = "no-cache";
context.Response.ContentType = "text/plain";
// TODO:
}
string cont = dt.Rows[i]["NewsContent"].ToString();
string temCode = tmhelper.getTimeCode() + ".htm";
改成 string title = convert.tostring(dt.Rows[i]["Title"])
.....
应该不是 如果它是break出去的 结果res就不会为1了
呵呵 星星多就是不一样,斑竹就是斑竹,就是tmhelper.getTimeCode()的问题 谢谢!!
string temCode = tmhelper.getTimeCode() + ".htm";估计是有相同的数据。