Skip to content

Instantly share code, notes, and snippets.

@justsayantan
Created August 15, 2019 14:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justsayantan/c05c30301463b283c8742ecfa234a9ee to your computer and use it in GitHub Desktop.
Save justsayantan/c05c30301463b283c8742ecfa234a9ee to your computer and use it in GitHub Desktop.
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