Skip to content

Instantly share code, notes, and snippets.

@justsayantan
Last active June 6, 2018 10:51

Revisions

  1. justsayantan revised this gist Jun 6, 2018. 1 changed file with 18 additions and 26 deletions.
    44 changes: 18 additions & 26 deletions AddItemToBundle.PS1
    Original file line number Diff line number Diff line change
    @@ -12,38 +12,30 @@ Function AddItemToBundle
    )

    Begin
    {
    $client = Get-TridionCoreServiceClient -Verbose:($PSBoundParameters['Verbose'] -eq $true);
    }
    {
    $client = Get-TridionCoreServiceClient -Verbose:($PSBoundParameters['Verbose'] -eq $true);
    $readOptions = New-Object Tridion.ContentManager.CoreService.Client.ReadOptions;
    }

    Process
    {
    $readOptions = New-Object Tridion.ContentManager.CoreService.Client.ReadOptions;
    $bundle = Get-TridionItem -id $BundleId
    [xml]$bundleConfiguration = $bundle.Configuration
    [xml]$bundelItems = $bundleConfiguration.Bundle.Items.OuterXml
    [System.Xml.XmlNameTable] $nameTable = $bundleConfiguration.NameTable
    [System.Xml.XmlNamespaceManager] $namespaceManager = $nameTable;
    $namespaceManager.AddNamespace('b', 'http://www.sdltridion.com/ContentManager/Bundle');
    $namespaceManager.AddNamespace('xlink', 'http://www.w3.org/1999/xlink');
    $bundle = Get-TridionItem -id $BundleId;

    [System.Xml.XmlNode] $itemsElement = $bundleConfiguration.SelectSingleNode("/b:Bundle/b:Items", $namespaceManager);
    $doc = New-Object System.Xml.XmlDocument;
    $doc.LoadXml($bundle.Configuration)

    [System.Xml.XmlElement] $itemElement = $itemsElement.OwnerDocument.CreateElement('Item', 'http://www.sdltridion.com/ContentManager/Bundle');
    [System.Xml.XmlAttribute] $xmlAttr = $itemElement.OwnerDocument.CreateAttribute('xlink', 'href', 'http://www.w3.org/1999/xlink');
    $xmlAttr.Value = $ItemID;
    [System.Xml.XmlAttribute] $xmlAttr1 = $itemElement.OwnerDocument.CreateAttribute('xlink', 'type', 'http://www.w3.org/1999/xlink');
    $xmlAttr1.Value = "simple";
    $itemElement.SetAttributeNode($xmlAttr);
    $itemElement.SetAttributeNode($xmlAttr1);
    $itemsElement.AppendChild($itemElement);
    $bundle.Configuration = $bundleConfiguration.InnerXml;
    $client.Save($bundle, $readOption);
    }
    $itemElem = $doc.CreateElement('Item', $BundleNamespace);
    $itemElem.SetAttribute('href', $XLinkNamespace, $itemId) | Out-Null;

    $rootElem = $doc.SelectSingleNode('/*/*');
    $rootElem.appendChild($itemElem) | Out-Null;

    $bundle.Configuration = $doc.InnerXml;
    $client.Save($bundle, $readOptions);
    }
    End
    {
    Close-TridionCoreServiceClient $client;
    }
    {
    Close-TridionCoreServiceClient $client;
    }

    }
  2. justsayantan revised this gist Jun 5, 2018. 1 changed file with 0 additions and 1 deletion.
    1 change: 0 additions & 1 deletion AddItemToBundle.cs
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,6 @@ public static void AddItemToBundle(string bundleId, string itemId)
    {
    CoreServiceClient _CoreServiceClient = Utility.GetCoreServiceSettings();
    ReadOptions _readOption = new ReadOptions();
    //string bundleId = "tcm:5-1076-8192";
    VirtualFolderData bundle = (VirtualFolderData)_CoreServiceClient.Read(bundleId, _readOption);
    XmlDocument bundleConfiguration = new XmlDocument();
    bundleConfiguration.LoadXml(bundle.Configuration);
  3. justsayantan revised this gist Jun 5, 2018. 1 changed file with 3 additions and 3 deletions.
    6 changes: 3 additions & 3 deletions AddItemToBundle.PS1
    Original file line number Diff line number Diff line change
    @@ -6,9 +6,9 @@ Function AddItemToBundle
    [Parameter(Mandatory=$true)]
    [string]$BundleId,

    # Item ID .
    [Parameter(Mandatory=$true)]
    [string]$ItemID
    # Item ID .
    [Parameter(Mandatory=$true)]
    [string]$ItemID
    )

    Begin
  4. justsayantan revised this gist Jun 5, 2018. 1 changed file with 28 additions and 0 deletions.
    28 changes: 28 additions & 0 deletions AddItemToBundle.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    public static void AddItemToBundle(string bundleId, string itemId)
    {
    CoreServiceClient _CoreServiceClient = Utility.GetCoreServiceSettings();
    ReadOptions _readOption = new ReadOptions();
    //string bundleId = "tcm:5-1076-8192";
    VirtualFolderData bundle = (VirtualFolderData)_CoreServiceClient.Read(bundleId, _readOption);
    XmlDocument bundleConfiguration = new XmlDocument();
    bundleConfiguration.LoadXml(bundle.Configuration);

    XmlNameTable nameTable = new NameTable();
    nameTable = bundleConfiguration.NameTable;
    XmlNamespaceManager namespaceManager = new XmlNamespaceManager(nameTable);
    namespaceManager.AddNamespace("b", @"http://www.sdltridion.com/ContentManager/Bundle");
    namespaceManager.AddNamespace("xlink", @"http://www.w3.org/1999/xlink");

    XmlNode itemsElement = bundleConfiguration.SelectSingleNode("/b:Bundle/b:Items", namespaceManager);

    XmlElement itemElement = itemsElement.OwnerDocument.CreateElement("Item", @"http://www.sdltridion.com/ContentManager/Bundle");
    XmlAttribute xmlAttr = itemElement.OwnerDocument.CreateAttribute("xlink", "href", "http://www.w3.org/1999/xlink");
    xmlAttr.Value = itemId;
    XmlAttribute xmlAttr1 = itemElement.OwnerDocument.CreateAttribute("xlink", "type", "http://www.w3.org/1999/xlink");
    xmlAttr1.Value = "simple";
    itemElement.SetAttributeNode(xmlAttr);
    itemElement.SetAttributeNode(xmlAttr1);
    itemsElement.AppendChild(itemElement);
    bundle.Configuration = bundleConfiguration.InnerXml;
    _CoreServiceClient.Save(bundle, _readOption);
    }
  5. justsayantan created this gist Jun 5, 2018.
    49 changes: 49 additions & 0 deletions AddItemToBundle.PS1
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,49 @@
    Function AddItemToBundle
    {
    [CmdletBinding()]
    Param (
    # Bundle ID
    [Parameter(Mandatory=$true)]
    [string]$BundleId,

    # Item ID .
    [Parameter(Mandatory=$true)]
    [string]$ItemID
    )

    Begin
    {
    $client = Get-TridionCoreServiceClient -Verbose:($PSBoundParameters['Verbose'] -eq $true);
    }

    Process
    {
    $readOptions = New-Object Tridion.ContentManager.CoreService.Client.ReadOptions;
    $bundle = Get-TridionItem -id $BundleId
    [xml]$bundleConfiguration = $bundle.Configuration
    [xml]$bundelItems = $bundleConfiguration.Bundle.Items.OuterXml
    [System.Xml.XmlNameTable] $nameTable = $bundleConfiguration.NameTable
    [System.Xml.XmlNamespaceManager] $namespaceManager = $nameTable;
    $namespaceManager.AddNamespace('b', 'http://www.sdltridion.com/ContentManager/Bundle');
    $namespaceManager.AddNamespace('xlink', 'http://www.w3.org/1999/xlink');

    [System.Xml.XmlNode] $itemsElement = $bundleConfiguration.SelectSingleNode("/b:Bundle/b:Items", $namespaceManager);

    [System.Xml.XmlElement] $itemElement = $itemsElement.OwnerDocument.CreateElement('Item', 'http://www.sdltridion.com/ContentManager/Bundle');
    [System.Xml.XmlAttribute] $xmlAttr = $itemElement.OwnerDocument.CreateAttribute('xlink', 'href', 'http://www.w3.org/1999/xlink');
    $xmlAttr.Value = $ItemID;
    [System.Xml.XmlAttribute] $xmlAttr1 = $itemElement.OwnerDocument.CreateAttribute('xlink', 'type', 'http://www.w3.org/1999/xlink');
    $xmlAttr1.Value = "simple";
    $itemElement.SetAttributeNode($xmlAttr);
    $itemElement.SetAttributeNode($xmlAttr1);
    $itemsElement.AppendChild($itemElement);
    $bundle.Configuration = $bundleConfiguration.InnerXml;
    $client.Save($bundle, $readOption);
    }

    End
    {
    Close-TridionCoreServiceClient $client;
    }

    }