>> 출처: 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시간 허비 했습니다.. ^^
'Tech: > .NET·C#' 카테고리의 다른 글
C/C++로 넘겨준 한글 문자열 다시 받아 처리하기 (0) | 2008.06.26 |
---|---|
CAPICOM IL 수정하여 다시 빌드하기 (0) | 2008.06.26 |
Visual Studio 2005 ASP.NET 팁 (0) | 2008.06.26 |
ASP.NET에서 RSACryptoServiceProvider 사용하기 (0) | 2008.06.26 |
[펌] ViewState Compression (0) | 2008.06.26 |