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

2 posts, 0 answered
  1. Jacques
    Jacques avatar
    427 posts
    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)
    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();
    07.    //if (document != null)
    08.    //{
    09.    //    document = librariesManager.Lifecycle.GetLive(document) as Telerik.Sitefinity.Libraries.Model.Document;
    10.    //}
    12.    TermsAndCondtions.HRef = doc.Url;

    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: 


    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
    23 May 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);

    Svetoslav Manchev
    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
2 posts, 0 answered