using System;
using System.Web;
using CDO;
using System.Text;
using System.Runtime.InteropServices.ComTypes;
using System.Web.Mail;
using ADODB;
 
namespace Venetian.Portal.BO.ContentManagement
{
    public class SaveFile
    {
        //private ctor as our methods are all static here
        private SaveFile()
        {
 
        }
 
        public static byte[] SaveWebPageToMHTFile(string url)
        {
            //bool result = false;
            CDO.Message msg = new CDO.MessageClass();
            byte[] byteArray;
            ADODB.Stream stm = null;
            try
            {
                msg.MimeFormatted = true;
                msg.CreateMHTMLBody(url, CDO.CdoMHTMLFlags.cdoSuppressNone, "", "");
                stm = msg.GetStream();
                IStream iStream = (IStream)stm;
                byteArray = new byte[stm.Size];
                IntPtr ptrCharsRead = IntPtr.Zero;
                iStream.Read(byteArray, stm.Size, ptrCharsRead);
 
                //System.IO.Stream stream = (System.IO.Stream)msg.GetStream();
                //stm.SaveToFile(filePath, ADODB.SaveOptionsEnum.adSaveCreateOverWrite);
                msg = null;
                stm.Close();
                //result = true;
            }
            catch
            { throw; }
 
            return byteArray;
        }
 
    }
}