Created
August 15, 2019 14:58
-
-
Save justsayantan/c05c30301463b283c8742ecfa234a9ee to your computer and use it in GitHub Desktop.
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 string getcomponentid() | |
{ | |
var client = Utility.GetCoreServiceSettings(); | |
string result = "Item not found"; | |
string TargetFolderTcmId = @"/webdav/200%20Master%20Content%20(ENG)/Building%20Blocks/Content/"; // Put your folder's webdav url or tcm uri here | |
string title = @"Component Title";// Put your component title here | |
var productsXML = | |
client.GetListXml(TargetFolderTcmId, | |
new OrganizationalItemItemsFilterData | |
{ | |
ItemTypes = new[] { ItemType.Component } | |
}); | |
//loop through each item and find out if it is the product we want already exist | |
foreach (var product in productsXML.Elements()) | |
{ | |
tcmID = product.Attribute("ID").Value; | |
var productData = client.Read(product.Attribute("ID").Value, null) as ComponentData; | |
var schemaFields = client.ReadSchemaFields(productData.Schema.IdRef, false, null); | |
XNamespace ns = schemaFields.NamespaceUri; | |
//check if the product id's match | |
if ((XDocument.Parse(productData.Content)).Root.Element(ns + "heading") != null) | |
{ | |
if (Id == (XDocument.Parse(productData.Content)).Root.Element(ns + "heading").Value) | |
{ | |
return tcmID; | |
} | |
} | |
} | |
return String.Empty; | |
} | |
catch (Exception Ex) | |
{ | |
return string.Empty; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment