This step-by-step article describes how to automate the MapPoint 2002 control and save the map as HTML in Visual C# .NET.
The MapPoint Control
The Microsoft MapPoint Control 9.0 is an ActiveX control that is included with Microsoft MapPoint 2002. This control provides a convenient way to implement MapPoint 2002 functionality on a form in a Visual C# .NET project. By using this control, you can access most, but not all, MapPoint 2002 functionality. For example, you cannot programmatically save a map in the HTML format with the ActiveX control, but you can save the map as a MapPoint .ptm file by using the control, and then programmatically open the .ptm file in MapPoint and save it as HTML. This article contains sample code that demonstrates this solution.
Steps to Build the Sample
The MapPoint 9 Control installs its own type library and a version of the MapPoint 2002 type library, but not all of the latter. For this example, you need the complete MapPoint 2002 type library as well as the partial type library that ships with the control to build an instance of the Application object. The type library for MapPoint 2002 has a namespace attribute that conflicts with the namespace of the version that is supplied (imported) by the control; when you import the MapPoint 2002 type library, you can use a different namespace to avoid this conflict.
Import the MapPoint Type Library
From the Programs list on the Start menu, click Microsoft Visual Studio .NET, click Visual Studio .NET Tools, and then click Visual Studio .NET CommandPrompt.
NOTE: If you did not install MapPoint to the default installation folder, modify the value of objTemplate in Form1_Load so that the path to the template matches your installation of MapPoint.
Test the Sample
Press F5 to build and run the program. Form1 loads with a map of North America.
Click Make Route Map. MapPoint draws a route map from a starting point, through a midpoint, through another midpoint, and back to the endpoint (which is the same as the starting point). The timed itinerary appears in a list box above the map. A copy of the displayed map is saved as C:\Atestmap.ptm.
Click Save Map as HTML. On your hard drive, you now see the C:\Atestmap.htm file. Double-click the file to see your route map in your Web browser.
Click Close the Project to dispose of Form1 and the map.