日期:2014-05-17  浏览次数:20406 次

关闭进程
用模板生成静态页,但是生成的html文件有的不能访问,关闭VS在重新打开就可以访问了
怎样用代码关闭现在的进程

 protected void Button1_Click(object sender, EventArgs e)
    {
        StreamWriter sw = null;
        StreamReader sr = null;
        string htmlfilename = "";
        string str1 = "";
        string path1 = HttpContext.Current.Server.MapPath("i.htm");//模板
        string path = HttpContext.Current.Server.MapPath("~/html/");//生成文件放在html文件夹下
        try
        {
            sr = new StreamReader(path1, Encoding.GetEncoding("GB2312"));
            str1 = sr.ReadToEnd();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            sr.Close();
            sr.Dispose();
        }
        try
        {
            for (int i = 0; i < 4; i++)
            {

                htmlfilename = ""+ i +".html";
                sw = new StreamWriter(path + htmlfilename, false, Encoding.GetEncoding("GB2312"));
                str1 = str1.Replace("$i$", i.ToString());
                sw.Write(str1);
                sw.Flush();
            }
        }
        catch (Exception ex)
        {
            HttpContext.Current.Response.Write(ex);
            HttpContext.Current.Response.End();
        }
        finally
        {
            sw.Close();
            sw.Dispose();
        }<