Поделиться через


How to Retrieve Site Terms

For the latest version of Commerce Server 2007 Help, see the Microsoft Web site.

To retrieve a site term, you must know its name. You can retrieve a site term by using code or by using the Commerce Server Manager. This topic shows how to retrieve a site term in code.

To retrieve a site term

  1. Add a drop-down list box to your Web page and name it ElementList. This list box will contain a list of all elements in the site term.

  2. Create a ProfileContext object. This object is used to interact with the Profiles System runtime.

  3. Call the GetSiteTerm method and pass it the site term that you are trying to retrieve.

  4. Bind the XML structure results of the GetSiteTerm method call to the drop-down list box by assigning the DataSource property to the Elements property of the site term result.

  5. Assign the DataTextField property of the drop-down list box to "Name" and assign the DataValueField to "Value".

  6. Initiate the binding process by calling the DataBind method of the drop-down list.

Example

This example shows how to write site code that retrieves a specific site term from the Profiles System.

// Declare variables.
SiteTerm mySiteTerm = null;
string siteTerm = "Locations";

try
{
    // Get runtime object.
    ProfileContext ctxt = CommerceContext.Current.ProfileSystem;

    // Get Site term.
    mySiteTerm = ctxt.GetSiteTerm(siteTerm);

    ElementList.DataSource = mySiteTerm.Elements;
    ElementList.DataTextField = "Name";
    ElementList.DataValueField = "Value";
    ElementList.DataBind();

    // Success!
    Console.WriteLine("Successfully retrieved site term.");

}
catch (Exception ex)
{
    Console.WriteLine("Exception: {0}\r\nMessage: {1}", ex.GetType(), ex.ToString());
    if (ex.InnerException != null)
    {
        Console.WriteLine("\r\nInner Exception: {0}\r\nMessage: {1}", ex.InnerException.GetType(), ex.InnerException.Message);
    }
}

Compiling the Code

  • To compile the code, you need to include these namespace directives:
using Microsoft.CommerceServer.Runtime;
using Microsoft.CommerceServer.Runtime.Profiles;

See Also

Other Resources

How to Use Site Terms

Site Terms Concepts and Tasks

How to Create and Update Site Terms

How to Delete Site Terms