0

I'm trying to create a Sitecore package programmatically in sc9.3.

It's only one item which has 0 en versions & one ja-JP version. However, when the package is created, it only has the en folder.

SourceCollection<PackageEntry> sourceCollection = new 
SourceCollection<PackageEntry>();
Item item = database.Items.GetItem(itemPath);

if (item != null)
{
   foreach (Language language in item.Languages)
   {
      itemByLanguage = item.Database.GetItem(item.ID, language);

      if (itemByLanguage != null && itemByLanguage.Versions.Count > 0)
      {
         sourceCollection.Add(new ItemSource()
         {
             SkipVersions = true,
             Database = itemByLanguage.Uri.DatabaseName,
             Root = itemByLanguage.Uri.ItemID.ToString()
          });
       }
   }                    
}

I have even tried setting the SkipVersions to false, but there is no change.
On debug, it only adds the ja-Jp fine. Why is this folder not created then.

UPDATE:
The above code is to add items with subitems in the package. If I add just the parent item, then it works fine. The code for adding individual items is like this:

ExplicitItemSource packageItemSource = new ExplicitItemSource
{
   Name = "Items Source"
};
sourceCollection.Add(packageItemSource);    
Item item = database.Items.GetItem(itemPath);

if (item != null)
{
    foreach (Language language in item.Languages)
    {
       itemByLanguage = item.Database.GetItem(item.ID, language);

       if (itemByLanguage != null && itemByLanguage.Versions.Count > 0)
       {
           packageItemSource.Entries.Add(new ItemReference(itemByLanguage.Uri, false).ToString());
        }
     }
 }
  • 1
    Have you tried with SkipVersions = false? – Marek Musielak Mar 16 at 17:12
  • @MarekMusielak It's the same even with SkipVersions = fasle; – Qwerty Mar 17 at 4:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.