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();

解决方案 »

  1.   

     string sql = "select top 10 *  from gb_NewsInfo order by ID desc";
      

  2.   

    头上加上这段试试看,可以去除缓存的影响。        public void ProcessRequest(HttpContext context)
            {
                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:
    }
      

  3.   

    肯定是你的数据有问题 string title = dt.Rows[i]["Title"].ToString();
                        string cont = dt.Rows[i]["NewsContent"].ToString();
                        string temCode = tmhelper.getTimeCode() + ".htm";
    改成 string title = convert.tostring(dt.Rows[i]["Title"])
    .....
      

  4.   

    tmhelper.getTimeCode() + ".htm";看下这个方法.同时看看生成的文件 里面内容是第几条数据的
      

  5.   

    你断点看看是不是到第三条的时候从break跳出去了
      

  6.   


    应该不是  如果它是break出去的  结果res就不会为1
      

  7.   


    呵呵  星星多就是不一样,斑竹就是斑竹,就是tmhelper.getTimeCode()的问题  谢谢!!
      

  8.   

     string cont = dt.Rows[i]["NewsContent"].ToString();
     string temCode = tmhelper.getTimeCode() + ".htm";估计是有相同的数据。