Create *. Mht file (web archive)

Use the following function view to create a web archive from a local html file

function TLessonConstructor2.CreateMHT( const FileName : string):boolean ; var oMSG:IMessage; oConfig: IConfiguration; sFileName: string; Stream: _Stream; begin //CoInitializeEx(nil, COINIT_APARTMENTTHREADED); //CoInitialize(nil); try Result := false; sFileName := ChangeFileExt(FileName, '.mht'); DeleteFile(PAnsiChar(sFileName)); try oConfig := CoConfiguration.Create(); oMSG := CoMessage.Create(); oMSG.Configuration := oConfig; oMSG.CreateMHTMLBody(FileName,CdoSuppressNone,'',''); Stream:=oMSG.GetStream; Stream.SaveToFile(sFileName,adSaveCreateOverWrite); Stream.Cancel; Stream.Close; Result := True; except on E: Exception do begin Result := false; MessageDlg(E.Message, mtError, [mbOK], 0); end; end; finally // CoUnInitialize; Stream:=nil; oConfig:=nil; oMSG:=nil; end; end; 

FileName is the full path to the html.

After executing oMSG.CreateMHTMLBody (file_name, CdoSuppressNone, '', '') ; This file is locked until the main process is complete. However, this file should be deleted after processing.

Any idea what the problem is?

+4
source share
1 answer

CreateMHTMLBody requires a URL, so for a local file preceded by file:///

  CreateMHTMLBody (const URL: WideString; Flags: CdoMHTMLFlags; 
                           const UserName: WideString;  const Password: WideString);  safecall;
+3
source

Source: https://habr.com/ru/post/1437378/


All Articles