// ExStart:SavingToStream private static void SavingToStream(HtmlSaveOptions.HtmlPageMarkupSavingInfo htmlSavingInfo) { byte[] resultHtmlAsBytes = new byte[htmlSavingInfo.ContentStream.Length]; htmlSavingInfo.ContentStream.Read(resultHtmlAsBytes, 0, resultHtmlAsBytes.Length); // Here You can use any writable stream, file stream is taken just as example string fileName = "stream_out.html"; Stream outStream = File.OpenWrite(fileName); outStream.Write(resultHtmlAsBytes, 0, resultHtmlAsBytes.Length); }
// ExStart:SaveHTMLImageCSSHelper private static void StrategyOfSavingHtml(HtmlSaveOptions.HtmlPageMarkupSavingInfo htmlSavingInfo) { // Get target file name and write content to it System.IO.BinaryReader reader = new BinaryReader(htmlSavingInfo.ContentStream); byte[] htmlAsByte = reader.ReadBytes((int)htmlSavingInfo.ContentStream.Length); Console.WriteLine("Html page processed with handler. Length of page's text in bytes is " + htmlAsByte.Length.ToString()); // Here You can put code that will save page's HTML to some storage, f.e database MemoryStream targetStream = new MemoryStream(); targetStream.Write(htmlAsByte, 0, htmlAsByte.Length); }