Try Now
More in this section

Forums / Developing with Sitefinity / Querying documents within different providers

Querying documents within different providers

2 posts, 0 answered
  1. Daniel
    Daniel avatar
    3 posts
    16 Apr 2013
    10 Jun 2014
    Link to this post

    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?

  2. Stefani Tacheva
    Stefani Tacheva avatar
    718 posts
    19 Oct 2016
    12 Jun 2014
    Link to this post

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

    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();

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