将动态页面转换成静态页

 

将动态页面转换成静态页、、、

参数:

savePath:生成静态页的保存路径

saveName:生成静态页的命名

sourceUrl:转换成静态页的动态页Url

请朋友注意一下引用、、、

代码如下:

using System;
using System.Data;
using System.Configuration;
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;
using System.Text;
using System.Net;

/// <summary>
/// SysImports 的摘要说明
/// 静态页面生成类
/// </summary>
public class SysImports
{
    private Encoding code = Encoding.GetEncoding("utf-8");

    /*************************************
     * 生成静态页
     *************************************/
    public void createHtml(string savePath, string saveName, string sourceUrl)
    {
        StreamReader sr = null;
        StreamWriter sw = null;
        string str = null;

        //判断路径是否存在
        if (Directory.Exists(HttpContext.Current.Server.MapPath(savePath)) == false)
        {
            //创建路径
            Directory.CreateDirectory(HttpContext.Current.Server.MapPath(savePath));
        }

        WebRequest temp = WebRequest.Create(sourceUrl);
        WebResponse mytemp = temp.GetResponse();

        sr = new StreamReader(mytemp.GetResponseStream(), _code);
        try
        {
            sr = new StreamReader(mytemp.GetResponseStream(), _code);
            str = sr.ReadToEnd();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            sr.Close();
        }

        try
        {
            sw = new StreamWriter(HttpContext.Current.Server.MapPath(savePath) + saveName, false, code);
            sw.Write(str);
            sw.Flush();
        }
        catch (Exception ex)
        {
            throw ex;
        }
        finally
        {
            sw.Close();
        }
    }
}

工作总是可以积累许经验、、、

转载于:https://www.cnblogs.com/IT-SmallBird/archive/2011/11/02/2233477.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值