Question

I found the following difference between the old VBScript API and the .Net API:

In the old VBScript API it's possible to invoke "TDSE.getObject" to retrieve a Tridion object passing by the webdav path, an integer to select how to open it (read only, read and write, etc) and the ID of the publication where there is the exact element of the blueprint we want.

In the new .Net API all I found was "Engine.GetObject" but it only receives the TCM ID or the webdav path of an element.

Our scenario is the following; in the old VBScript code, this overload of the getObject method was used to avoid some permission issues detected while using TCM IDs instead of the webdav paths and because it's much more handful when you need to copy the code between different environments (see DEV, PREPROD and PROD for example), avoiding changing TCM IDs.

So my questions are:

  1. Is there and overload like the old one in the new .Net API?
  2. If not, is there a way of retrieving items by webdav keeping in mind that some of them could be localized and changed from their parent? (the old way works with this, if you send the root webdav path it will retrieve local objects even if their names aren't exactly the same as the parents)

Thank you!

Was it helpful?

Solution

Do you want to be able to use the webdav url of the top-level item, and specify the publication id from which to get the item?

I would create an extension method on Engine that does this for you:

public static T GetObject<T>(this Engine engine, string webDavUrl, int publicationId)
    where T : IdentifiableObject
{
    [logic to retreive the item and then if needed
     get the correct tcm uri and get the intended item]

    return item as T;
}

However, this is quite an expensive operation since you get two objects instead of one. So I dont know if I would use this method very often.

OTHER TIPS

Here some samples

IdentifiableObject item = engine.GetObject(new TcmUri("tcm:5-677")); 
//will give you the latest approved version in the publication 5.

IdentifiableObject item = engine.GetObject(new TcmUri("tcm:5-677-v0")); 
//will give you the WF or Editable version.

TcmUri uri = new TcmUri("tcm:5-677");
uri.PublicationId = 6;
IdentifiableObject item = engine.GetObject(uri); 
//will give you the latest approved version in the publication 6.

Engine.GetObject has 4 overloaded method.

GetObject(Session, string)

GetObject(string)

GetObject(TcmUri)

GetObject(Item)

You can check the Tom.Net Api for more details.

Actually, using Engine.GetObject Method (String) should work.

public virtual IdentifiableObject GetObject(
    string itemUriOrWebDavUrl
)

You can do something in this way:-

  1. Get the Object based on WebDav URL
  2. Get the TCM ID from this object
  3. Based on your publication, modified your TCM ID accordingly and do your stuff

OR

Try something this way too:-

Repository testRepository = (Repository)session.GetObject("tcm:0-2-1");
Component testComponent = (Component)testRepository.GetObject(webdavURL); //Assuming actual TCM ID is "tcm:1-3"
Console.WriteLine(testComponent.Id); // should show "tcm:2-3"
// Do Your Other Stuff
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top