ApiExamples.ExDocument.InsertHtmlFromWebPage C# (CSharp) Метод

InsertHtmlFromWebPage() приватный Метод

private InsertHtmlFromWebPage ( ) : void
Результат void
        public void InsertHtmlFromWebPage()
        {
            //ExStart
            //ExFor:Document.#ctor(Stream, LoadOptions)
            //ExFor:LoadOptions.#ctor(LoadFormat, String, String)
            //ExFor:LoadFormat
            //ExSummary:Shows how to insert the HTML conntents from a web page into a new document.
            // The url of the page to load 
            String url = "http://www.aspose.com/";

            // Create a WebClient object to easily extract the HTML from the page.
            WebClient client = new WebClient();
            String pageSource = client.DownloadString(url);
            client.Dispose();

            // Get the HTML as bytes for loading into a stream.
            Encoding encoding = client.Encoding;
            byte[] pageBytes = encoding.GetBytes(pageSource);

            // Load the HTML into a stream.
            MemoryStream stream = new MemoryStream(pageBytes);

            // The baseUri property should be set to ensure any relative img paths are retrieved correctly.
            LoadOptions options = new LoadOptions(Aspose.Words.LoadFormat.Html, "", url);

            // Load the HTML document from stream and pass the LoadOptions object.
            Document doc = new Document(stream, options);

            // Save the document to disk.
            // The extension of the filename can be changed to save the document into other formats. e.g PDF, DOCX, ODT, RTF.
            doc.Save(MyDir + @"\Artifacts\Document.HtmlPageFromWebpage.doc");
            //ExEnd
        }
ExDocument