Solved

Automate IE File>Save As

Posted on 2002-04-05
4
230 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

With most software applications trying to cater to multiple user needs nowadays, the focus is to make them as configurable as possible. For e.g., when creating Silverlight applications which will connect to WCF services, the service end point usuall…
After several hours of googling I could not gather any information on this topic. There are several ways of controlling the USB port connected to any storage device. The best example of that is by changing the registry value of "HKEY_LOCAL_MACHINE\S…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
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…

786 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