Click here to Skip to main content
15,892,674 members
Articles / Programming Languages / C#

Harvesting Web Content into MHTML Archive

Rate me:
Please Sign up or sign in to vote.
4.69/5 (14 votes)
18 Feb 20068 min read 62K   729   49  
Capture and archive web resources by saving them in RFC-2557 (MHTML) compliant format. This library includes a framework for augmenting the capture process and allowing programmatic control, from downloading through saving. A replacement for CDOSYS/CDONTS.
using System;
using System.IO;
using Rilling.Web.Mhtml.IO;
using NUnit.Framework;

namespace Rilling.Web.Mhtml.TestHarness
{
	[TestFixture()]
	public class MhtmlTextWriterTest
	{
		[Test()]
		public void WriteMessageHeader1_MethodTest()
		{
			MemoryStream mhtBase = new MemoryStream();

			MhtmlTextWriter writer = new MhtmlTextWriter( mhtBase );
							writer.WriteMessageHeader("MIME Version", "1.0");
							writer.Flush();

			//mhtBase.Seek(0, SeekOrigin.Begin);
			StreamReader reader = new StreamReader( mhtBase );
			string testValue = reader.ReadLine();

			Assertion.AssertEquals("MIME Version: 1.0", testValue);
		}

		[Test()]
		public void WriteMessageHeader2_WithoutParams_MethodTest()
		{
			MemoryStream mhtBase = new MemoryStream();

			HeaderParameter hp1 = new HeaderParameter("charset", "us-ascii");
			HeaderParameter hp2 = new HeaderParameter("boundary", "__myboundary__");

			MhtmlTextWriter writer = new MhtmlTextWriter( mhtBase );
							writer.WriteMessageHeader("Content-Type", "text/html", hp1, hp2);

			StreamReader reader = new StreamReader( mhtBase );

			string testValue = reader.ReadLine();
			Assertion.AssertEquals("Content-Type: text/html", testValue);

			testValue = reader.ReadLine();
			Assertion.AssertEquals("\tcharset=\"us-ascii\";", testValue);

			testValue = reader.ReadLine();
			Assertion.AssertEquals("\tboundary=\"__myboundary__\"", testValue);
		}

		[Test()]
		public void WriteMessageHeader2_MethodTest()
		{
		}

		[Test()]
		public void WriteMessageHeader3_MethodTest()
		{
		}
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Software Developer (Senior)
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions