>> 출처: http://blog.naver.com/saga111/120019677272


 

//****************************** 사용법 **********************************

//MHT 파일 저장

//사용하기 위하여 Microsoft CDO For Exchange 2000 Library 를 참조하여야만 한다.

//왜냐하면 그걸 이용하여 만드는 거니깐.. ^^
SaveMHTResult = SaveMHT(h_content, r_ItemID, r_BoardID, textBox1.Text.Trim());
if (SaveMHTResult == false)
{
     MessageBox.Show("ERROR:MHT 파일을 저장하는데 실패하였습니다.");
 }

 

//****************************** 사용함수**********************************

//Mht 파일을 저장하기 위한 함수
  public bool SaveMHT(string strHTML, string strMHTFilename, string strBoardID, string strFilePath)
  {
   string DocPath = "";
   string mhtfilePath = "";

   try
   {
    strHTML = strHTML.Replace("'", "'");
      
    DocPath = strFilePath + "\\";
      
    if (System.IO.Directory.Exists(DocPath + strBoardID) == false)
    {
     System.IO.Directory.CreateDirectory(DocPath + strBoardID);
     System.IO.Directory.CreateDirectory(DocPath + strBoardID + "\\UploadFile");
     System.IO.Directory.CreateDirectory(DocPath + strBoardID + "\\doc");
    }

    mhtfilePath = DocPath + strBoardID + "\\doc\\" + strMHTFilename + ".htm";
    string mhtfilePath2 = DocPath + strBoardID + "\\doc\\" + strMHTFilename + ".mht";
   
    //StremWriter를 이용하여 임시 HTML파일을 생성한다.
    if (System.IO.File.Exists(mhtfilePath)) System.IO.File.Delete(mhtfilePath);
    StreamWriter output = new StreamWriter(mhtfilePath, false, System.Text.Encoding.Default);
    output.WriteLine(strHTML);
    output.Close();

    //등록된 Html파일의 URL 주소를 가져 와서 CDO객체를 이용하여 MHT를 생성 한다.
    string fileURL = @"html을 저장할 절대 경로위치".htm";
    CDO.Message iMsg = new CDO.MessageClass();
    iMsg.CreateMHTMLBody(fileURL,0,"","");

    //등록된 Html파일의 URL 주소를 가져 와서 CDO객체를 이용하여 MHT를 생성 한다.
    if (System.IO.File.Exists(mhtfilePath2)) System.IO.File.Delete(mhtfilePath2);
    ADODB.Stream streamStr = new ADODB.StreamClass();
    streamStr = iMsg.GetStream();
    streamStr.SaveToFile(mhtfilePath2,ADODB.SaveOptionsEnum.adSaveCreateOverWrite);

    streamStr.Close();

    //등록된 Html파일을 삭제 한다.
    if (System.IO.File.Exists(mhtfilePath)) System.IO.File.Delete(mhtfilePath);   

    return true;
   }
   catch(Exception e)
   {
    MessageBox.Show(e.Message);
    return false;
   }    

  }

 

 

어렵지 않으니 대략 보시고 참고하세요.. ^^ 전 이거 만드느라 4시간 허비 했습니다.. ^^




Posted by 떼르미
,


자바스크립트를 허용해주세요!
Please Enable JavaScript![ Enable JavaScript ]