Searching the Windows Phone 7 Marketplace Programmatically


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

Comments (6)

  1. Stéphane says:

    Hello.

    What I want to do is to be able to :

    – if the other application is already install : launch it

    – else show the marketplace detail task as show here

    How can I do the first thing ?

  2. dohollan says:

    Hey Stéphane

    Unfortunately you cannot launch another application on Windows Phone 7 programmatically although obviously, given that was what this blog post was about, you can always refer the user to the marketplace.

    It's a good sugestion although you'd likely need the user to allow you to start the given application. I'll be sure to mention it to the team although I don't know if they will do this in the future.

    Regards,

    – Doug

  3. Ben Cameron says:

    Hi, great post thanks!

    I am wondering if its possible to download content from the marketplace to then use in the app? For example can I do a search for a content identifer and instead of being directed to the market place I get back an object or xml (or something else) that details the marketplace content (eg album artist, track names etc…)?

    Is this possible?

  4. Ben Cameron says:

    Hi

    Is there a way to search the marketplace and get the result returned as xml to use in a app?

  5. dohollan says:

    Hey Ben,

    Unfortunately that's not possible at the moment and we'd have to explore more usage scenarios for such a feature. Is that feature available on other mobile marketplaces?

    With respect to your second question, presently the marketplace URL's are processed by the Zune software although it would be useful to maybe expose the marketplace as an ODATA feed which could be consumed by an application.

    zune://navigate/?appID=d35631f4-8c02-e011-9264-00237de2db9e

    Regards,

    – Doug

  6. Gavin Earley says:

    Great post. This is very helpful.