Using .net I'd like to pull write a class that will pull component information based on the component's tcmid that is passed to id. Could someone point me to documentation or/and samples that could point me in the right direction?
-
Define "information"? What are you looking to get? The content within the component? Metadata? Publish info? Webdavurl?– Bjørn van DommelenCommented Jan 24, 2015 at 15:34
-
Unrelated to this specific question, I see that you have yet to accept an answer to any of your questions. You might want to read up on StackExchange etiquette: meta.stackexchange.com/questions/5234/…– Frank van PuffelenCommented Jan 24, 2015 at 19:55
-
I'm looking to get at content within the component.– FreqCommented Jan 26, 2015 at 14:07
2 Answers
I assume you want to do it via the Core Service: Take a look at these links:
Core Service Client Sample Code
Changing Components’ Schemas With Core Service
That should give you some material to read.
This sample code will allow you to "read" a component from .net using the Core Service and access some of its data:
String id="tcm:1-1"; //Your component id
ComponentData comp = Tridion.Read(id, new ReadOptions()) as ComponentData;
FullVersionInfo info = comp.VersionInfo as FullVersionInfo;
String creator = info.Creator.Title +" [" + info.Creator.IdRef + "]";
String created = info.CreationDate.Value.ToNiceDate();
String modified = info.RevisionDate.Value.ToNiceDate();
String folderId = comp.LocationInfo.OrganizationalItem.IdRef.ToString();
String folderTitle = comp.LocationInfo.OrganizationalItem.Title;
String schemaId = comp.Schema.IdRef.ToString();
String schemaName = comp.Schema.Title;
In regards to Alvin's comment:
If what you need is to get data using the Content Delivery API, you might want to read the answers to this question: Unable to get specific field value from component.
It will explain the "basics" of Content Management vs. Content Delivery contexts. In a nutshell, whatever you need to access in the content delivery, you need to make available in the content delivery, normally by "publishing". When you publish the content gets rendered with templates and they will "produce" the data you want (be it html, xml, json, etc...). Once the data is available in the Broker Database (Content Delivery data store), you can read it using any of the available APIs (.Net, oData).
-
Actually I read ".NET" and thought Content Delivery, Jaime. :-) To add context for Freq's question, Jaime's example would be for a Content Manager-side integration with what's stored in Tridion. For a .NET website/web project that Tridion publishes to, we use the published Component Presentations, the Content Delivery API, or Content Delivery Webservice to get Component "information" based on what you need and the setup. Commented Jan 24, 2015 at 20:36
-
I'm looking to pull information prior to publishing-by calling a usercontrol from within a component template. So, I'm looking to access component info in the Content Management context.– FreqCommented Jan 26, 2015 at 14:18
-
1I recommend you attend an SDL Tridion Foundation Training and then the Developer Track. It seems like you don't have much experience with the CMS archtiecture. Commented Jan 26, 2015 at 14:21
To read Component content from template side, below is the information
- Firstly you need to get the object
Type cast the object as Component
Component mComponent = mEngine.GetObject(ID) as Component;
To get the component XML
XmlElement componentXml = mComponent.ToXml();
To get the components content only
XmlElement componentContent = mComponent.Content;
To get the components metadata only
XmlElement componentMetadata = mComponent.Metadata;