Within the Microsoft.Phone.Tasks namespace there are several types that allow you to interact with the Windows Phone 7 marketplace. We’ll explore these types and see how you can search the Windows Phone 7 marketplace programmatically.

Let’s start with a simple marketplace search using the MarketplaceSearchTask class.

MarketplaceSearchTask

As you can see in the above class diagram, the MarketplaceSearchTask class contains two properties. The ContentType property allows us to specify, through the MarkeplaceContentType enumeration, whether the search is for Applications or Music. The SearchTerms property then allows us to specify a string containing the search terms for our marketplace search.

MarketplaceSearchTask task = new MarketplaceSearchTask();

task.ContentType = MarketplaceContentType.Applications;

task.SearchTerms = "Doug Holland Stopwatch";

task.Show();

Using the above code the application will redirect the user to the marketplace as shown here within the Windows Phone 7 emulator.

Marketplace Search

What if we want the user to be directed directly to the information page for that application rather than the search results page?  Let’s now take a look at the MarketplaceDetailTask class.

MarketplaceDetailTask

While the MarketplaceDetailTask class also contains the ContentType property as before, it also allows us to specify a string representing the ContentIdentifier or Product ID from the AppHub.

MarketplaceDetailTask task = new MarketplaceDetailTask();

task.ContentType = MarketplaceContentType.Applications;

task.ContentIdentifier = "d35631f4-8c02-e011-9264-00237de2db9e";

task.Show();

Using the above code the application will redirect the user to the application information page within the marketplace, as shown here within the Windows Phone 7 emulator.

image

Another type within the Microsoft.Phone.Tasks namespace is the MarketplaceReviewTask class that allows us to redirect the user to the marketplace such that they can write a review of the application.

MarketplaceReviewTask

With the MarketplaceReviewTask class there are no properties to set as it will internally direct to the marketplace for the application within which is has been called.

MarketplaceReviewTask task = new MarketplaceReviewTask();

task.Show();

When using this code within a sample application, using either the Windows Phone 7 emulator or a developer unlocked phone, you’ll see the following error when the application cannot be found for the user to review.

Marketplace Review

The last type within the Microsoft.Phone.Tasks namespace is the MarketplaceHubTask class that allows us to redirect the user to the marketplace for applications or music. Within the following code we’ll open the marketplace for applications by specifying the ContentType property to the appropriate value within the MarkeplaceContentType enumeration.

MarketplaceHubTask task = new MarketplaceHubTask();

task.ContentType = MarketplaceContentType.Applications;

task.Show();

Using the above code the application will redirect the user to the the marketplace, as shown here within the Windows Phone 7 emulator.

Marketplace Hub

We’ll now use the following code to open the marketplace for music, again by specifying the appropriate value within the MarkeplaceContentType enumeration for the ContentType property.

MarketplaceHubTask task = new MarketplaceHubTask();

task.ContentType = MarketplaceContentType.Music;

task.Show();

Using the above code the application will redirect the user to the Zune music marketplace, as shown here within the Windows Phone 7 emulator.

ZuneIronWine