How to Delete Site Terms
To delete a site term, you must know its name. You can delete the site term in code or by using the Commerce Server Manager. You can delete site terms in your code by following the procedure outlined in this topic.
To delete a site term
Create a ProfilesServiceAgent object. This agent will be used to connect to the Profiles Web service.
Set the agent credentials that you want to use with the Profiles Web service by setting the Credentials property.
Create a ProfileManagementContext object by passing it the ProfilesServiceAgent object that you created in step 1.
Call the DeleteSiteTerm method, and specify the name of the site term you want to delete.
Example
The following code sample deletes a specific site term.
try
{
// Connect to the Profiles Web service by using the agent.
ProfilesServiceAgent agent = new ProfilesServiceAgent("https://localhost/ProfilesWebService/ProfilesWebService.asmx");
agent.Credentials = CredentialCache.DefaultNetworkCredentials;
ProfileManagementContext ctxt = ProfileManagementContext.Create(agent);
// Delete the site term called "Locations".
ctxt.DeleteSiteTerm("Locations");
// Success!
Console.WriteLine("Successfully deleted site term.");
}
catch (Exception ex)
{
Console.WriteLine("Exception: {0}\r\nMessage: {1}", ex.GetType(), ex.Message);
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 the following namespace directive:
using Microsoft.CommerceServer.Profiles;