62,046
社区成员
发帖
与我相关
我的任务
分享
StringWriter wr = new StringWriter();
Server.Execute("abc.aspx", wr);
File.WriteAllText(Server.MapPath("abc.html"), wr.ToString());
HTMLstr = ReadFile("ATemplateHTML_EN.htm");
//替换模版的标签
HTMLstr = HTMLstr.Replace("$Link[1]$", "/SC"+Path+""+alldt.Rows[i]["Project_No"].ToString() + ".html");
//----------生成htm文件------------------――
try
{
using (StreamWriter sw = new StreamWriter(dirPath + alldt.Rows[i]["Project_No"].ToString() + ".html", false, Encoding.UTF8)) //保存地址
{
sw.WriteLine(HTMLstr);
sw.Flush();
sw.Close();
}
}
catch(Exception ex)
{
Response.Write("The file could not be wirte:");
}
public string ReadFile(string TemplatePath)
{
//---------------------读html模板页面到stringbuilder对象里----
StringBuilder htmltext = new StringBuilder();
try
{
using (StreamReader sr = new StreamReader(Server.MapPath(".") + "/" + TemplatePath + "")) //模板页路径
{
String line;
while ((line = sr.ReadLine()) != null)
{
htmltext.Append(line);
}
sr.Close();
}
return htmltext.ToString();
}
catch
{
return "";
}
}
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
namespace Web.Admin
{
public partial class Admin_MakeIndex : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
CommFun.IsAdmin();
if (!IsPostBack)
{
string url = Request.Url.AbsoluteUri.Substring(0, Request.Url.AbsoluteUri.LastIndexOf("/admin")); //获取网址
url += "/default.aspx"; //首页文件
string text;
System.Net.WebRequest wReq = System.Net.WebRequest.Create(url);
System.Net.WebResponse wResp = wReq.GetResponse(); //注意要先 using System.IO;
System.IO.Stream respStream = wResp.GetResponseStream();
System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("gb2312"));
text = reader.ReadToEnd();
string path = System.Web.HttpContext.Current.Server.MapPath("../default.html");
using (System.IO.StreamWriter sw = new System.IO.StreamWriter(path, false, System.Text.Encoding.UTF8))
{
if (text.Trim() != "")
{
sw.Write(text);
Response.Write("首页生成成功!");
}
}
}
}
}
}
public class HtmlMaker
{
public static void Make(string source, string direction)
{
string fullPath = System.Web.HttpContext.Current.Request.Url.Authority;
string url = "http://" + fullPath + source;
Uri uri = new Uri(url);
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
using (Stream resStream = response.GetResponseStream())
{
using (StreamReader sr = new StreamReader(resStream, Encoding.GetEncoding("gb2312")))
{
string result = sr.ReadToEnd();
using (StreamWriter sw = new StreamWriter(System.Web.HttpContext.Current.Server.MapPath(direction), false, Encoding.GetEncoding("gb2312")))
{
sw.Write(result);
}
}
}
}
}