Solved

Automate IE File>Save As

Posted on 2002-04-05
4
235 Views
Last Modified: 2013-12-03
I have an application that needs to:

1) Open a URL.
2) Do a File>Save As of type TEXT
3) Open the text file and do some processing on it for a report.

I know how to do everything but #2, i.e. get the HTML document currently open in IE to be saved in the TXT format.
0
Comment
Question by:jhance
  • 2
  • 2
4 Comments
 
LVL 86

Accepted Solution

by:
jkr earned 100 total points
ID: 6921180
See http://support.microsoft.com/support/kb/articles/Q292/4/85.ASP ('HOWTO: Programmatically Save an HTML Page to Disk'). The scoop is:

Accomplishing this task from a Visual C++ host is very straightforward. You can use an IWebBrowser2
interface to call the QueryInterface method for the IHTMLDocument2 interface. After you obtain a pointer
to the document, then call QueryInterface for the IPersistFile interface. After you obtain this interface
pointer, you can call the save method to save the file to disk.

   HRESULT          hr    = E_FAIL;
   IDispatch*       pDisp = NULL;
   IHTMLDocument2*  pDoc  = NULL;
   
   pDisp                  = m_webOC.GetDocument();

  if(SUCCEEDED(hr = pDisp->QueryInterface(IID_IHTMLDocument2,(void**)&pDoc)))
  {
      IPersistFile*     pFile     =     NULL;
      if(SUCCEEDED(pDoc->QueryInterface(IID_IPersistFile,(void**)&pFile)))
      {
    LPCOLESTR     file = L"c:\\test1.htm";
    pFile->Save(file,TRUE);
      }
  }
0
 
LVL 32

Author Comment

by:jhance
ID: 6921202
Exactly what I was looking for.  Thanks!
0
 
LVL 32

Author Comment

by:jhance
ID: 6921211
Am I just dumb or are all these IE related COM interfaces poorly documented and arcane?

I suppose they make perfect sense to those folks at Microsoft but I can never find what I need...
0
 
LVL 86

Expert Comment

by:jkr
ID: 6921262
>>Am I just dumb or are all these IE related COM interfaces poorly documented

Well, there's  only one chance - if you come across such an article, bookmark it instantly :o)
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows a few slightly more advanced techniques for Windows 7 gadget programming, including how to save and restore user settings for your gadget and how to populate the "details" panel that is displayed in the Windows 7 gadget gallery.  …
This article describes a technique for converting RTF (Rich Text Format) data to HTML and provides C++ source that does it all in just a few lines of code. Although RTF is coming to be considered a "legacy" format, it is still in common use... po…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question