欧美日韩一区二区三区四区不卡,日韩欧美视频一区二区三区四区,久久精品欧美一区二区三区不卡,国产精品久久久乱弄

咨詢電話:186 7916 6165 咨詢電話:186 7916 6165 (微信同號)    在線QQ:181796286
NEWS BLOG ·
學(xué)無止境
關(guān)注開優(yōu)網(wǎng)絡(luò) 關(guān)注前沿
ASP.NET使用一般處理程序生成驗證碼
Excel導(dǎo)入導(dǎo)出

ASP.NET生成HTML靜態(tài)頁類

發(fā)表日期:2015-09-28    文章編輯:南昌開優(yōu)網(wǎng)絡(luò)    瀏覽次數(shù):4059    標(biāo)簽:ASP.NET應(yīng)用


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Net;
using System.IO;
using System.Text;
using System.Web.UI.HtmlControls;
using System.Text.RegularExpressions;

/// <summary>
///CreateHtml 的摘要說明
/// </summary>
public class CreateHtml:System.Web.UI.Page
{
public CreateHtml()
{
//
//TODO: 在此處添加構(gòu)造函數(shù)邏輯
//
}
    /// <summary>
    /// 生成靜態(tài)頁面,生成位置是本項目下
    /// </summary>
    /// <param name="strURL">請求的URL</param>
    /// <param name="strRelPath">創(chuàng)建的路徑及文件名,路徑為相對路徑</param>
    public bool Nei_Create(string strURL, string strRelPath)
    {
        string  strFilePage;
      
        strFilePage = HttpContext.Current.Server.MapPath(strRelPath);
        StreamWriter sw = null;
        //獲得aspx的靜態(tài)html
        try
        {
            
            if (File.Exists(strFilePage))
            {
                File.Delete(strFilePage);
            }
            sw = new StreamWriter(strFilePage, false, System.Text.Encoding.GetEncoding("gb2312"));
            System.Net.WebRequest wReq = System.Net.WebRequest.Create(strURL);
            System.Net.WebResponse wResp = wReq.GetResponse();
            System.IO.Stream respStream = wResp.GetResponseStream();
            System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("gb2312"));
            string strTemp = reader.ReadToEnd();

            Regex r1 = new Regex("<input type=\"hidden\" name=\"__EVENTTARGET\".*/>", RegexOptions.IgnoreCase);
            Regex r2 = new Regex("<input type=\"hidden\" name=\"__EVENTARGUMENT\".*/>", RegexOptions.IgnoreCase);
            Regex r3 = new Regex("<input type=\"hidden\" name=\"__VIEWSTATE\".*/>", RegexOptions.IgnoreCase);

            Regex r4 = new Regex("<form .*id=\"form1\">", RegexOptions.IgnoreCase);
            Regex r5 = new Regex("</form>");

            Regex r6 = new Regex("<input type=\"hidden\" name=\"__EVENTVALIDATION\".*/>", RegexOptions.IgnoreCase);
            strTemp = r1.Replace(strTemp, "");
            strTemp = r2.Replace(strTemp, "");
            strTemp = r3.Replace(strTemp, "");
            strTemp = r4.Replace(strTemp, "");
            strTemp = r5.Replace(strTemp, "");
            strTemp = r6.Replace(strTemp, "");

            sw.Write(strTemp);
        }
        catch (Exception ex)
        {
            HttpContext.Current.Response.Write(ex.Message);
            HttpContext.Current.Response.End();
            return false;//生成到出錯
        }
        finally
        {
            sw.Flush();
            sw.Close();
            sw = null;
        }

        return true;
    }
    /// <summary>
    /// 生成靜態(tài)頁面,生成位置不在本項目下
    /// </summary>
    /// <param name="strURL">請求的URL</param>
    /// <param name="strRelPath">創(chuàng)建的路徑及文件名,路徑為絕對路徑</param>
    public bool Wai_Create(string strURL, string strRelPath,string filename)
    {
        string strFilePage;
        strFilePage = strRelPath + "\\" + filename;
        StreamWriter sw = null;
        //獲得aspx的靜態(tài)html
        try
        {
            if (!Directory.Exists(strRelPath))
            {
                Directory.CreateDirectory(strRelPath);
            }
            if (File.Exists(strFilePage))
            {
                File.Delete(strFilePage);
            }
            sw = new StreamWriter(strFilePage, false, System.Text.Encoding.GetEncoding("gb2312"));
            System.Net.WebRequest wReq = System.Net.WebRequest.Create(strURL);
            System.Net.WebResponse wResp = wReq.GetResponse();
            System.IO.Stream respStream = wResp.GetResponseStream();
            System.IO.StreamReader reader = new System.IO.StreamReader(respStream, System.Text.Encoding.GetEncoding("gb2312"));
            string strTemp = reader.ReadToEnd();

            Regex r1 = new Regex("<input type=\"hidden\" name=\"__EVENTTARGET\".*/>", RegexOptions.IgnoreCase);
            Regex r2 = new Regex("<input type=\"hidden\" name=\"__EVENTARGUMENT\".*/>", RegexOptions.IgnoreCase);
            Regex r3 = new Regex("<input type=\"hidden\" name=\"__VIEWSTATE\".*/>", RegexOptions.IgnoreCase);

            Regex r4 = new Regex("<form .*id=\"form1\">", RegexOptions.IgnoreCase);
            Regex r5 = new Regex("</form>");

            Regex r6 = new Regex("<input type=\"hidden\" name=\"__EVENTVALIDATION\".*/>", RegexOptions.IgnoreCase);
            strTemp = r1.Replace(strTemp, "");
            strTemp = r2.Replace(strTemp, "");
            strTemp = r3.Replace(strTemp, "");
            strTemp = r4.Replace(strTemp, "");
            strTemp = r5.Replace(strTemp, "");
            strTemp = r6.Replace(strTemp, "");

            sw.Write(strTemp);
        }
        catch (Exception ex)
        {
            HttpContext.Current.Response.Write(ex.Message);
            HttpContext.Current.Response.End();
            return false;//生成到出錯
        }
        finally
        {
            sw.Flush();
            sw.Close();
            sw = null;
        }

        return true;

    }
    public void FilePicDelete(string path)
    {
        System.IO.FileInfo file = new System.IO.FileInfo(path);
        if (file.Exists)
            file.Delete();
    }
}


主站蜘蛛池模板: 绥芬河市| 五指山市| 闽清县| 察雅县| 勃利县| 南川市| 思南县| 张北县| 丰宁| 东源县| 祥云县| 凌云县| 常熟市| 汉中市| 益阳市| 阜新市| 柳州市| 西乌珠穆沁旗| 若尔盖县| 海安县| 广昌县| 武威市| 定州市| 即墨市| 清远市| 临高县| 镶黄旗| 瓦房店市| 绍兴县| 武夷山市| 陆河县| 沅陵县| 巴东县| 福鼎市| 故城县| 乌什县| 牙克石市| 屏东县| 白银市| 禹州市| 洪洞县|