Ejemplo n.º 1
0
        public static bool SaveWebPageToMHTFile(string url, string filePath)
        {
            bool result = false;

            CDO.Message msg = new CDO.MessageClass();
            ADODB.Stream stm = null;
            try
            {
                msg.MimeFormatted = true;
                msg.CreateMHTMLBody(url, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
                stm = msg.GetStream();
                stm.SaveToFile(filePath, ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
                msg = null;
                stm.Close();
                result = true;
            }
            catch
            {
                throw;
            }
            finally
            {
                //cleanup here
            }

            return result;
        }
Ejemplo n.º 2
0
    public static void SaveToMHT(string strOutputFile, string data)
    {
        string tmpFileName = string.Format("Export{0}.html", DateTime.Now.Ticks);
        string strPath     = Path.GetTempPath();

        if (!Directory.Exists(strPath))
        {
            Directory.CreateDirectory(strPath);
        }
        string strFilePath = Path.Combine(strPath, tmpFileName);     //Server.MapPath(string.Format("./{0}", m_tmpFile));

        using (StreamWriter sw = File.CreateText(strFilePath))
        {
            sw.Write(data);
            sw.Close();
        }
        string url = "file://" + strFilePath;     // GetBaseURL() + m_tmpFile;

        CDO.MessageClass message = new CDO.MessageClass();
        ADODB.Stream     stream  = null;

        try
        {
            message.CreateMHTMLBody(url, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
            stream = message.GetStream();
            stream.SaveToFile(strOutputFile, ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
        }
        catch (Exception)
        {
            using (FileStream fs = File.Create(strOutputFile))
            {
                using (BinaryWriter sw = new BinaryWriter(fs))
                {
                    sw.Write(new byte[] { 0xFF, 0xFE });
                    sw.Write(System.Text.Encoding.Unicode.GetBytes(data));     //.Unicode. strHTML.ToCharArray()); //Write(strHTML);
                    sw.Close();
                }
            }
        }
        finally
        {
            if (stream != null)
            {
                stream.Close();
            }
        }

        if (File.Exists(strFilePath))
        {
            File.Delete(strFilePath);
        }
    }
Ejemplo n.º 3
0
        public static string ConvertWebPageToMHTString(string url)
        {
            string data = String.Empty;

            CDO.Message msg = new CDO.MessageClass();
            ADODB.Stream stm = null;
            try
            {
                msg.MimeFormatted = true;
                msg.CreateMHTMLBody(url, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
                stm = msg.GetStream();
                data = stm.ReadText(stm.Size);
            }
            catch
            {
                throw;
            }
            finally
            {
                //cleanup here
            }

            return data;
        }