Import Categories to Catalog

Vote:
 

I am attempting to write a scheduled job that imports our existing categories into the CMS using the content model.  The problem that I am seeing is that I have a catalog, but I cannot insert my newly created categories directly to the catalog.  Instead I have to manually create a dummy category with a code, then insert my new categories, via the code, into the system where the parent Link is a reference to the manually created dummy category.  Is there a way to insert directly to the catalog since I don't want the extra layer in the catalog tree.

#150300
Jun 15, 2016 17:19
Vote:
 

Of course, you just have to get the ContentReference of your Catalog instead, and use that as parentLink. As you've noticed the catalog has no Code that you can pass to the ReferenceConverter (which I assume you're using) to get the ContentReference. Instead, you need to get the numeric ID of the catalog and use another method overload on ReferenceConverter to pass it the catalog id, the CatalogContentType.Catalog enum and workId 0. Another way to find the catalog is to call IContentRepository.GetChildren with the RootLink field of the ReferenceConverter. This will give you the list of your existing catalogs (which are always children of the root), and you can find the appropriate catalog e.g. by its name. 

#150307
Jun 15, 2016 20:56
Vote:
 

Terrific, thank you Magnus.

#150311
Jun 15, 2016 21:58
This topic was created over six months ago and has been resolved. If you have a similar question, please create a new topic and refer to this one.
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.