Querying documents within different providers

Posted by Community Admin on 04-Aug-2018 12:53

Querying documents within different providers

All Replies

Posted by Community Admin on 10-Jun-2014 00:00

Within code i'm trying to retrieve a document by id. Our customer is using different libraries to save these documents.

When i use the  LibrariesManager librariesManager = LibrariesManager.GetManager(); and librariesManager.GetDocuments(), it only get's me the documents that are located within the default library.

When i use the provider name: LibrariesManager librariesManager = LibrariesManager.GetManager("librariesProvider6"); , it retrieves the documents that are within the right library. 

Could someone tell me, how i can retrieve all documents of all providers without providing a provider within the constructor?

Posted by Community Admin on 12-Jun-2014 00:00

Hello,

You could use the following code:

var manager = Telerik.Sitefinity.Modules.Libraries.LibrariesManager.GetManager();
var context = Telerik.Sitefinity.Data.OpenAccessExtensions.GetContext((Telerik.Sitefinity.Data.IOpenAccessDataProvider)manager.Provider);
context.GetAll<Telerik.Sitefinity.Libraries.Model.Image>();

Which will get all images from the database of the current project. Note that if there are other providers that are using different databases Open Access with not get this images using the method above.

You could filter by title using the following code:

var images = context.GetAll<Telerik.Sitefinity.Libraries.Model.Image>().Where(o => o.FieldValue<string>("Title_").Equals("Test")).ToList();


The other option is to use SitefinityQuery. The approach is better one because changes and information pass through Sitefinity:

var images = SitefinityQuery.Get<Telerik.Sitefinity.Libraries.Model.Image>(manager.Provider).Where(im => im.Title == "Test").ToList();


Regards,
Stefani Tacheva
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
 

This thread is closed