1-888-365-2779
+1-888-365-2779
Try Now
More in this section

Forums / Developing with Sitefinity / LibrariesManager.Lifecycle.GetLive returns null even though the document is published

LibrariesManager.Lifecycle.GetLive returns null even though the document is published

3 posts, 0 answered
  1. Jacques
    Jacques avatar
    427 posts
    Registered:
    28 Jun 2007
    20 Apr 2016
    Link to this post

    I'm trying to extract the URL for a published document in a custom widget built in an external project. 

    The code is as follows: 

    01.if (LinkToTermsAndConditions != Guid.Empty)
    02.{
    03.    var doc = Telerik.Sitefinity.App.WorkWith().Document(documentGuid).GetLive().Get() as Telerik.Sitefinity.Libraries.Model.Document;
    04.    //LibrariesManager librariesManager = new LibrariesManager();
    05.    //var document = librariesManager.GetDocuments().Where(d => d.Id == documentGuid).FirstOrDefault();
    06. 
    07.    //if (document != null)
    08.    //{
    09.    //    document = librariesManager.Lifecycle.GetLive(document) as Telerik.Sitefinity.Libraries.Model.Document;
    10.    //}
    11. 
    12.    TermsAndCondtions.HRef = doc.Url;
    13.}

    I've tried both the Fluent and normal approaches and in both cases if I just get the document, it retrieves it successfully but as soon as I try to get the current live version, it returns null. 

    In line 3 above, the Fluent version, I get an exception "An exception of type 'System.Reflection.AmbiguousMatchException' occurred in mscorlib.dll but was not handled in user code"

    However when I run: 

    1.Telerik.Sitefinity.App.WorkWith().Document(documentGuid).Get().Url

    I get a document URL.

    I've confirmed that the document, a PDF, is definitely published. 

    Why does the call to Lifecycle.GetLive always return null? 

  2. Svetoslav Manchev
    Svetoslav Manchev avatar
    735 posts
    Registered:
    06 Sep 2017
    25 Apr 2016
    Link to this post
    Hello Jacques,

    How the Id of the document is get? Testing the sample from that article:
    http://docs.sitefinity.com/for-developers-query-documents, seems working fine with both APIs using the following code:
    Native API:
    private Document GetDocumentNativeAPI(Guid masterDocumentId)
    {
        LibrariesManager librariesManager = LibrariesManager.GetManager();
        Document document = librariesManager.GetDocuments().Where(d => d.Id == masterDocumentId).FirstOrDefault();
     
        if (document != null)
        {
            document = librariesManager.Lifecycle.GetLive(document) as Document;
        }
     
        return document;
    }

    Fluent API:
    private Document GetDocumentFluentAPI(Guid masterDocumentId)
    {
        return App.WorkWith().Document(masterDocumentId).GetLive().Get();
    }


    The document is get by:
    var libManager = LibrariesManager.GetManager();
    var document = libManager.GetDocuments().Where(d => d.Title == "MyDocumentName").FirstOrDefault();
     
    var liveDocFluent = GetDocumentFluentAPI(document.Id);
    var liveDocNative = GetDocumentNativeAPI(document.Id);

    Regards,
    Svetoslav Manchev
    Telerik
     
    Do you want to have your say in the Sitefinity development roadmap? Do you want to know when a feature you requested is added or when a bug fixed? Explore the Telerik Sitefinity CMS Ideas&Feedback Portal and vote to affect the priority of the items
     
  3. Robert
    Robert avatar
    2 posts
    Registered:
    07 Mar 2014
    15 Jun
    Link to this post

    We are experiencing the exact same issue described by Jacques when retrieving DynamicContent items. Consider this code:

    Guid id = new Guid("ac5ccbf3-1c23-67bb-b384-ff0000f3621c");
     
    DynamicModuleManager manager = DynamicModuleManager.GetManager( string.Empty );
     
    var master = manager.GetDataItems( "Telerik.Sitefinity.DynamicTypes.Model.Procedures.Procedure" ).Where( i => i.Id == request.Id ).FirstOrDefault();    // returns live, visible item.
    var item = manager.Lifecycle.GetLive( master );     // returns null
     
    var masterTwo = manager.GetDataItem( "Telerik.Sitefinity.DynamicTypes.Model.Procedures.Procedure", request.Id );    // returns live, visible item.
    var temTwo = manager.Lifecycle.GetLive( masterTwo );    // returns null

     

    As far as I can tell, the master version returned from Sitefinity is the current version---no draft versions were created after the most-recent master version and all of the master item's properties suggest it is the published version---so that leaves us with this ugly workaround:

    // If the item is null and the master version is the published version, use the master version.
    if ( item == null && master.Id.Equals( id ) && master.Status == ContentLifecycleStatus.Live && master.Visible )
    {
        item = master;
    }

     

    Is there a reason manager.Workflow.GetLive() is not returning the published version of a content item even though one exists? 

3 posts, 0 answered