Last active
June 6, 2018 10:51
-
-
Save justsayantan/5a7012fba8c0ca75c1da0209031848c6 to your computer and use it in GitHub Desktop.
Script to add items to Bundle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void AddItemToBundle(string bundleId, string itemId) | |
{ | |
CoreServiceClient _CoreServiceClient = Utility.GetCoreServiceSettings(); | |
ReadOptions _readOption = new ReadOptions(); | |
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); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | |
$readOptions = New-Object Tridion.ContentManager.CoreService.Client.ReadOptions; | |
} | |
Process | |
{ | |
$bundle = Get-TridionItem -id $BundleId; | |
$doc = New-Object System.Xml.XmlDocument; | |
$doc.LoadXml($bundle.Configuration) | |
$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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment