webbrowser - ShowSaveAsDialog fails to save web page

I am loading content into webbrowser control via the DocumentText property and want to use the standard ShowSaveAsDialog().

This works fine when saving html only, however web page complete save an empty document and web archive throws an error dialog.

Do I need anything html specifc to enable these options I am creating the html by apply via a xsl transform and may not have included all the html ements that I need.

Thx, Nick



Answer this question

webbrowser - ShowSaveAsDialog fails to save web page

  • Marcelo de Oliveira (BR/SP)

    I met the same problem. Is there any talent can help us

  • MarcosArg

    Here's an exerpt of the MSDN library topic on ShowSaveAsDialog:

    Note

    This method allows users to save only the contents of the document as it was originally loaded. Any modifications made to the document at run time through the Document property are not persisted. For information on retrieving the run-time modifications, see How to: Access the HTML Source in the Managed HTML Document Object Model.

    So in other words, this seems to be a "feature" (and what a nice one!) of the web browser control. Here's how i do this:

    if (!Directory.Exists("C:\\Temp")) { Directory.CreateDirectory("C:\\Temp"); }
    string tempFileName = "C:\\Temp\\ff" + Guid.NewGuid().ToString() + ".html";
    StreamWriter writer = File.CreateText(tempFileName);
    writer.Write(webBrowser1.DocumentText);
    string tempDoc = webBrowser1.DocumentText;
    writer.Flush(); writer.Close();
    webBrowser1.Navigate(tempFileName);
    webBrowser1.ShowSaveAsDialog();
    webBrowser1.DocumentText = tempDoc;
    File.Delete(tempFileName);

    Pretty much a round way, but it is working fine!



  • webbrowser - ShowSaveAsDialog fails to save web page