// Create a memory stream object using (var mem = new MemoryStream()) using (var sw = new StreamWriter(mem)) { // Write the HTML Code into memory object sw.Write("<p>Hello, World! I love HTML!</p>"); // It is important to set the position to the beginning, since HTMLDocument starts the reading exactly from the current position within the stream sw.Flush(); mem.Seek(0, SeekOrigin.Begin); // Initialize a document from the string variable using (var document = new HTMLDocument(mem, ".")) { // Save the document to disk document.Save(Path.Combine(OutputDir, "load-from-stream.html")); } }