Select the product you need help with
How To Programmatically Save an HTML Page to DiskArticle ID: 292485 - View products that this article applies to. This article was previously published under Q292485 Summary
This article demonstrates how to programmatically save to disk an HTML page that has been loaded into Internet Explorer without prompting the user.
More information
As a Web browser control host, or an application that is automating Internet Explorer, you may find it useful to be able to programmatically save the currently loaded document to disk without user intervention. The following code samples illustrate how to accomplish this in both Visual C++ and Visual Basic. While the Visual Basic solution also works in Visual C++, you cannot implement the Visual C++ solution in Visual Basic.
Visual Basic SolutionYou can use the Internet Explorer Document Object Model to capture all of the HTML sources into a string variable. The string variable can then be written out to a text file and saved to disk.Visual C++ SolutionAccomplishing 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.ReferencesFor additional information, click the article numbers below
to view the articles in the Microsoft Knowledge Base:
206891
(http://support.microsoft.com/kb/206891/EN-US/
)
PRB: Value of outerHTML Does Not Match Original File
244757
(http://support.microsoft.com/kb/244757/EN-US/
)
How To Download a File Without Prompting
271868
For more information about the IPersistFile interface, see the following MSDN Web site:
(http://support.microsoft.com/kb/271868/EN-US/
)
BUG: IPersistStreamInit Not Available for a FRAME in a FRAMESET
http://msdn.microsoft.com/en-us/library/ms687223(VS.85).aspx For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:
(http://msdn.microsoft.com/en-us/library/ms687223(VS.85).aspx)
http://msdn.microsoft.com/ie/
(http://msdn.microsoft.com/ie/)
http://support.microsoft.com/iep
(http://support.microsoft.com/iep)
PropertiesArticle ID: 292485 - Last Review: October 24, 2012 - Revision: 4.0
| Article Translations
|


Back to the top








