| Austin Skyles [MSFT] 2004-07-09, 3:11 pm |
| The included code will traverse over all categories in the Catalog
"Adventure Works Catalog" and print out the categories. You can adapt this
code to be used in a your web page.
using System;
using System.Data;
using Microsoft.CommerceServer.Runtime.Catalog;
using Microsoft.CommerceServer.Runtime.Diagnostics;
namespace ListCategories
{
/// <summary>
/// Summary description for Class1.
/// </summary>
class ListCategories
{
static string connectionString = "Provider=SQLOLEDB.1;Integrated
Security=SSPI;Initial Catalog=\"CSharpSite_commerce\";Data Source=.;";
static string catalogName = "Adventure Works Catalog";
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main(string[] args)
{
CatalogContext context =
CatalogContext. CreateFromConnectionString(connectionStr
ing, new
ConsoleDebugContext(DebugMode.Production));
ProductCatalog pc = context.GetCatalog(catalogName);
DataSet rootCategories = pc.GetRootCategories();
foreach(DataRow row in rootCategories.Tables[0].Rows)
{
ShowCategory(pc, row["CategoryName"].ToString(), 0);
}
}
static void ShowCategory(ProductCatalog pc, string categoryName, int
depth)
{
for(int i=0;i<depth;i++)
{
Console.Write(" ");
}
Console.WriteLine("Category: {0}", categoryName);
Category cat = pc.GetCategory(categoryName);
DataSet categories = cat.GetChildCategories();
foreach(DataRow row in categories.Tables[0].Rows)
{
ShowCategory(pc, row["CategoryName"].ToString(), depth+1);
}
}
}
}
Austin Skyles
This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. © 2002 Microsoft Corporation. All rights
reserved.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm
Get Secure! For more info visit http://www.microsoft.com/security.
Please reply to the newsgroups only. Thanks
--------------------
Reply-To: "jorge" <agujas3@hotmail.com>
From: "jorge" <agujas3@hotmail.com>
Subject: How can i see all categories??help help help!!!
Date: Wed, 7 Jul 2004 09:29:05 +0200
Lines: 7
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.3790.0
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.3790.132
Message-ID: <#hdJZQ$YEHA.648@TK2MSFTNGP10.phx.gbl>
Newsgroups: microsoft.public.commerceserver.general
NNTP-Posting-Host: 202.red-80-38-81.pooles.rima-tde.net 80.38.81.202
Path:
cpmsftngxa06.phx.gbl!TK2MSFTNGXS01.phx.gbl!TK2MSFTNGXA05.phx.gbl!TK2MSFTNGP0
8.phx.gbl!TK2MSFTNGP10.phx.gbl
Xref: cpmsftngxa06.phx.gbl microsoft.public.commerceserver.general:14203
X-Tomcat-NG: microsoft.public.commerceserver.general
Hello!!
i´m develop a web site with commerce and i need see all categories to create
a browse page.
how can i create a loop that cross all categories, please help me!!! is very
important!!
|