Archive

Archive for the ‘SDL Tridion’ Category

Get details of item(component,schema etc…) through Buisness Connector in SDL Tridion

October 7, 2010 3 comments

This code helps us to retrieve all the details of a particular item.
I have used Business Connector to connect with sdl tridion.
This code is written in console application(c# .net)

public void Details()
{
      public StringBuilder stringbuilder = new StringBuilder();

      #region ..item details..
     
      string path;
      /*this is used to get template from external source,
      for which we have created a folder in our project named as temp
      in that we have a stringTemplate named as folder.st */
      path = Environment.CurrentDirectory + "\\temp";

      StringTemplateGroup grp = new StringTemplateGroup("myGroup", path);
      StringTemplate query = grp.GetInstanceOf("folder");

      /* this is to fetch details of the item for which id is specified */
      query.SetAttribute("itemuri", "tcm:88-11828");
            
      /* this connects to tridion */
      BusinessConnector service = new BusinessConnector();
      service.Credentials = new System.Net.NetworkCredential("administrator", "admin");

            
      string BC = service.execute("default", query.ToString(), null);
      Console.WriteLine(BC);

      /*stringbuilder is used to print out put on external file*/
      stringbuilder.AppendFormat(@"{0}",BC);
      stringbuilder.Append(Environment.NewLine);

      /*name of the file to which we have to store*/
      File.WriteAllText(@"c:\ShowComponentRaw.xml", stringbuilder.ToString());

            
      #endregion ..item details...
}

Here’s the template
/*save it as .st because its string template */
folder.st

<?xml version='1.0'?>
<tcmapi:Message xmlns:tcmapi="http://www.tridion.com/ContentManager/5.0/TCMAPI"
version="5.0" from="Nishant" failOnError="false">
<tcmapi:Request ID="Request1" preserve="false">
  <tcmapi:GetItem itemURI="$itemuri$" writeBinaryToDisk="true">
    <tcmapi:ItemFilter type="XMLReadAll"/>
  </tcmapi:GetItem>
</tcmapi:Request>
</tcmapi:Message>

Enjoy.. 😉 ..!!!

Categories: SDL Tridion Tags: , ,
%d bloggers like this: