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 okpower.Utility;
using System.Drawing;
using System.Drawing.Imaging;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    public string WebPreview(string url)
    {
        if (string.IsNullOrEmpty(url)) return string.Empty;
        string fold = "uploads/website/";//图片存放目录
        string physicsFold = Server.MapPath(fold);
        string name = url;
            name = name.Replace('/', '-');
            name = name.Replace(':', '_');
            name = name.Replace('&', '_');
            name = name.Replace(',', '_');
            name = name.Replace('\'', '_');
            name = name.Replace('"', '_');
            string fileName = name + ".jpg";
            fileName = fileName.Replace("http_--", "");
        if (!System.IO.File.Exists(physicsFold + fileName))
        {
            try
            {
                Bitmap image = okpower.Utility.WebPreview.GetWebPreview(new Uri(url));

                //保存图片数据
                image.Save(physicsFold + fileName, ImageFormat.Jpeg);
            }
            catch (Exception ex)
            {
                throw;
            }
        }
        return fold + fileName;
    }
    protected void bt_Click(object sender, EventArgs e)
    {
        this.Preview.InnerHtml = "<img src=\""+ WebPreview(TextBox1.Text)+"\"/>";
    }
}
