• 0

[C#]How can I save a web page as a html file?


Question

9 answers to this question

Recommended Posts

  • 0

I find a way

my WebBrowser object name is "wb"

    object doc = wb.Document;
    mshtml.HTMLDocumentClass c = (mshtml.HTMLDocumentClass) doc;

    System.IO.StreamWriter str = null;
    try
    {
    	str = new StreamWriter("C:\\saved.html");
    	str.Write( c.documentElement.outerHTML );
    }
    catch 
    {
    }
    finally
    {
    	if( str != null )
    	{
      str.Close();
    	}
    }

it just the way, in a really application you will need some additional codes

such as check if there is no pages loaded, and to open a save dialog and so on...

  • 0
  THE_BAT said:
I find a way

my WebBrowser object name is "wb"

 ? ?object doc = wb.Document;
 ? ?mshtml.HTMLDocumentClass c = (mshtml.HTMLDocumentClass) doc;

 ? ?System.IO.StreamWriter str = null;
 ? ?try
 ? ?{
 ? ?	str = new StreamWriter("C:\\saved.html");
 ? ?	str.Write( c.documentElement.outerHTML );
 ? ?}
 ? ?catch 
 ? ?{
 ? ?}
 ? ?finally
 ? ?{
 ? ?	if( str != null )
 ? ?	{
 ? ? ?str.Close();
 ? ?	}
 ? ?}

it just the way, in a really application you will need some additional codes

such as check if there is no pages loaded, and to open a save dialog and so on...

586480544[/snapback]

Thank you , and then how to read the html file and show it with object WebBrowser?? Ine:pcon' alt=':D' />guy in this filed. :p :D :cool: :D

  • 0
  THE_BAT said:
I find a way

my WebBrowser object name is "wb"

 ? ?object doc = wb.Document;
 ? ?mshtml.HTMLDocumentClass c = (mshtml.HTMLDocumentClass) doc;

 ? ?System.IO.StreamWriter str = null;
 ? ?try
 ? ?{
 ? ?	str = new StreamWriter("C:\\saved.html");
 ? ?	str.Write( c.documentElement.outerHTML );
 ? ?}
 ? ?catch 
 ? ?{
 ? ?}
 ? ?finally
 ? ?{
 ? ?	if( str != null )
 ? ?	{
 ? ? ?str.Close();
 ? ?	}
 ? ?}

it just the way, in a really application you will need some additional codes

such as check if there is no pages loaded, and to open a save dialog and so on...

586480544[/snapback]

These codes really works well on English WebPage, but not on Chinese WebPage, :yes:u know how to set the coding??? :yes:

  • 0
  zhwcn said:
These codes really works well on English WebPage, but not on Chinese WebPage,  do you know how to set the coding??? :yes:

586481435[/snapback]

i didn't work with Chinese before

but try to change the Encoding

change the following line

str = new StreamWriter("C:\\saved.html", false, System.Text.Encoding.Unicode);

or try the other Encoding

System.Text.Encoding.ASCII
System.Text.Encoding.BigEndianUnicode
System.Text.Encoding.UTF7  
System.Text.Encoding.UTF8

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Popular Now

  • Posts

    • Apple is making a scary move: a private company overchallenging a legit government and legislation. I am not a fan of democracy, but I am more scared of corporatism. The EU must take a strong stance now: Apple should comply with the law or face consequences, and it must do so immediately.
    • Intel LGA1700 14th Gen i5-14600K and 12th Gen 12600K are selling for great prices by Sayan Sen Intel is back again with another great CPU sale. We reported on the 14600K deal recently, which is now available for an even better price of just $195, and this includes a free AIO liquid cooler (purchase link under the specs list below). Aside from the 14th Gen i5, the 12th Gen 12600K is also available for just $125 (purchase link under the specs list below). Both chips are compatible with LGA1700 socket. First up, we have the Intel 14600K. The chip performs about as well as an AMD Ryzen 7600(X) in gaming and beats it in productivity. Since this is a socket LGA1700 SKU, buyers are advised to pair it up with a decent motherboard that has good VRM power delivery and cooling in place (ideally a Z790 chipset motherboard), plus you will need a good quality air cooler (and a complementary good case with excellent airflow) or a 240/280 mm AIO liquid cooler. The free MSI AIO cooler that comes with the bundle should suffice even for some moderate overclocking. Yes, overclocking is possible on both the 14600K and 12600K, as they are both K SKUs and thus are unlocked chips. The technical specs of the 14600K are given below: Core Count: 14 (6 Performance Cores + 8 Efficiency Cores) Thread Count: 20 Base Clock Frequency: 3.5 GHz (P-core), 2.6 GHz (E-core) Boost Clock Frequency: Up to 5.3 GHz Cache: 24 MB Cache Stock Memory Support: DDR4 (3200 MT/s) and DDR5 (5600 MT/s) Socket: LGA 1700 Base TDP: 125 W Integrated Graphics: Intel UHD Graphics 770 PCIe Support: PCIe Gen 5 and Gen 4 (16 lanes) Process Technology: Intel 7 (10 nm) Maximum Temperature: 100° C Get the 14600K at the link below: Intel Core i5-14600K BX8071514600K (additional $5 off w/ promo code SSET237, limited offer) + MSI MAG Coreliquid A13 240mm Liquid Cooler + Free Intel Spring Bundle (Civilization VII & Dying Light: The Beast): $194.99 (Sold and Shipped by Newegg US first-party seller) Up next we have the Core i5-12600K which tends to slot right in between Ryzen's 5000 series and 7000 series in gaming performance, typically trading blows with the 5800X3D. In productivity, it can get even with Ryzen's 7600(X) or a 5900X. The technical specs of the 12600K are given below: Core Count: 10 (6 Performance Cores + 4 Efficiency Cores) Thread Count: 16 Base Clock Frequency: 3.7 GHz (P-core), 2.8 GHz (E-core) Boost Clock Frequency: Up to 4.9 GHz Cache: 20 MB Cache Stock Memory Support: DDR4 (3200 MT/s) and DDR5 (4800 MT/s) Socket: LGA 1700 Base TDP: 125 W Integrated Graphics: Intel UHD Graphics 770 PCIe Support: PCIe Gen 5 and Gen 4 (16 lanes) Process Technology: Intel 7 (10 nm) Maximum Temperature: 100° C Get the 12600K at the link below: Core i5-12600K Processor Box, BX8071512600K: $125.33 (Amazon US) This Amazon deal is US-specific and not available in other regions unless specified. If you don't like it or want to look at more options, check out the Amazon US deals page here. Get Prime (SNAP), Prime Video, Audible Plus or Kindle / Music Unlimited. Free for 30 days. As an Amazon Associate, we earn from qualifying purchases.
    • Yes, this should have the Sponsored tag on it methinks.
    • Is there a conversion kit available so we can make it not look like something from a low-polygon video game from the 1990s?
    • "The company's core argument is that the changes mandated by the EU's DMA, which came into full effect in March 2024, introduce serious security and privacy risks for users. Apple claims that allowing sideloading and alternative app stores effectively opens the door for malware, fraud, scams, and other harmful content." I've heard this anti-sideloading argument a lot, but only from people who never wanted to sideload and will never do (so no risks for them), and from Apple themselves.
  • Recent Achievements

    • One Month Later
      EdwardFranciscoVilla earned a badge
      One Month Later
    • One Month Later
      MoyaM earned a badge
      One Month Later
    • One Month Later
      qology earned a badge
      One Month Later
    • One Year In
      Frinco90 earned a badge
      One Year In
    • Apprentice
      Frinco90 went up a rank
      Apprentice
  • Popular Contributors

    1. 1
      +primortal
      453
    2. 2
      +FloatingFatMan
      247
    3. 3
      snowy owl
      240
    4. 4
      ATLien_0
      196
    5. 5
      Xenon
      142
  • Tell a friend

    Love Neowin? Tell a friend!