zoukankan      html  css  js  c++  java
  • C# html转mht

    项目中引入cdosys.dll组件,位置:  C:WindowsSystem32cdosys.dll

    CDO、ADODB 这些类都来自于cdosys.dll组件

    /// <summary>
    /// 把Html格式二进制流转换成Mht格式的二进制流
    /// </summary>
    /// <param name="htmlUrl">Html格式的二进制流</param>
    /// <returns>Mht格式的二进制流</returns>
    public static byte[] ConvertHtmlUrlToMht(string htmlUrl)
    {
    string _CharSet = "gb2312";
    string strMhtContent = string.Empty;
    byte[] BytMhtContent = null;
    CDO.Message message = new CDO.MessageClass();
    ADODB.Stream stream = null;
    message.MimeFormatted = true;
    message.CreateMHTMLBody(htmlUrl, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
    stream = message.GetStream();
    stream.Charset = _CharSet;
    strMhtContent = stream.ReadText(stream.Size);
    BytMhtContent = Encoding.GetEncoding(_CharSet).GetBytes(strMhtContent);
    return BytMhtContent;
    }
    /// <summary>
    /// 把Html格式二进制流转换成Mht格式的二进制流,成功返回true,失败返回false
    /// </summary>
    /// <param name="htmlUrl">Html格式的二进制流</param>
    /// <param name="filePath">Mht文件的保存路径</param>
    /// <returns>操作结果 成功:true,失败;false</returns>
    public static bool ConvertHtmlUrlToMht(string htmlUrl, string filePath)
    {
    bool isConvertHtmlBytesToMht = false;
    CDO.Message message = new CDO.MessageClass();
    ADODB.Stream stream = null;
    message.MimeFormatted = true;
    message.CreateMHTMLBody(htmlUrl, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
    stream = message.GetStream();
    stream.SaveToFile(filePath, ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
    message = null;
    stream.Close();
    isConvertHtmlBytesToMht = true;
    return isConvertHtmlBytesToMht;
    }

  • 相关阅读:
    【Educational Codeforces Round 36 C】 Permute Digits
    【Educational Codeforces Round 36 B】Browser
    【Educational Codeforces Round 36 A】 Garden
    【习题 8-14 UVA
    【习题 8-13 UVA
    【习题 8-12 UVA
    【习题 8-11 UVA
    【习题 8-10 UVA
    关于货仓选址问题的方法及证明(在数轴上找一点使得该点到所有其他点的距离之和最小)
    P2512 [HAOI2008]糖果传递
  • 原文地址:https://www.cnblogs.com/zcm123/p/6087029.html
Copyright © 2011-2022 走看看