LibrariesManager.Lifecycle.GetLive returns null even though the document is published
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().UrlI 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?
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;private Document GetDocumentFluentAPI(Guid masterDocumentId) return App.WorkWith().Document(masterDocumentId).GetLive().Get();var libManager = LibrariesManager.GetManager();var document = libManager.GetDocuments().Where(d => d.Title == "MyDocumentName").FirstOrDefault();var liveDocFluent = GetDocumentFluentAPI(document.Id);var liveDocNative = GetDocumentNativeAPI(document.Id);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 nullvar 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?