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

Forums / Developing with Sitefinity / Document library displaying all documents

Document library displaying all documents

4 posts, 0 answered
  1. James
    James avatar
    3 posts
    Registered:
    19 Nov 2013
    19 Nov 2013
    Link to this post
    When I create a library programmatically and add documents to that library, the library shows as having all the documents (i.e. it displays "116 documents" under the title of the library. The problem is that when I "go into" the library I'm expecting to see just those documents, but instead it displays all of the documents in all of the libraries.

    If I go to Actions for that library and the edit properties and click "Save Changes" without altering anything then this seems to "fix" the issue. I.e. when I view the library it indicates at the top that it is only showing that library and does indeed only show the documents from that library.

    Below is the latest code that I'm using to create the library. I've been trying to see what other properties I could add that may help resolve the problem.

    We are using Sitefinity 6.1.

    Any help would be great.

    LibrariesManager libraryManager = LibrariesManager.GetManager();
                var library = libraryManager.GetDocumentLibraries().Where(l => l.Title == "LIbrary Title").FirstOrDefault();
                if (library == null)
                {
                    library = libraryManager.CreateDocumentLibrary(Guid.NewGuid());
                    library.Title = "Library Title";
                    library.UrlName = "Library Title".Replace(' ', '-');
                    library.DateCreated = DateTime.UtcNow;
                    library.LastModified = DateTime.UtcNow;
                    library.PublicationDate = DateTime.UtcNow;
                    library.Status = ContentLifecycleStatus.Master;
                    library.Description = "Library Title";
                    library.InheritsPermissions = true;
                    libraryManager.SaveChanges();
                }
  2. Daniel Plomp
    Daniel Plomp avatar
    952 posts
    Registered:
    18 Feb 2004
    19 Nov 2013 in reply to James
    Link to this post
    I can confirm this.
    I also create Libraries through the API, but also when creating new Libraries from the Backend UI, the filtering doesn't work?

    Kind regards,
    Daniel
  3. Petya
    Petya avatar
    123 posts
    Registered:
    17 Oct 2016
    20 Nov 2013
    Link to this post
    Hello,

    Thank you for contacting Sitefinity Support.

    It seems that the problem is coming from the fact the library is created without item_default_url. This is causing troubles when you want to filter the documents by the corresponding library.

    In order to fix the issue, just include the following line:
       
    libraryManager.RecompileAndValidateUrls(library);

    in the code below:

    LibrariesManager libraryManager = LibrariesManager.GetManager();
    var library = libraryManager.GetDocumentLibraries().Where(l => l.Title == "LIbrary Title").FirstOrDefault();
    if (library == null)
    {
        library = libraryManager.CreateDocumentLibrary(Guid.NewGuid());
        library.Title = "Library Title";
        library.UrlName = "Library Title".Replace(' ', '-');
        library.DateCreated = DateTime.UtcNow;
        library.LastModified = DateTime.UtcNow;
        library.PublicationDate = DateTime.UtcNow;
        library.Status = ContentLifecycleStatus.Master;
        library.Description = "Library Title";
        library.InheritsPermissions = true;
        libraryManager.RecompileAndValidateUrls(library);
        libraryManager.SaveChanges();
    }

    If you have any additional questions, do not hesitate to contact us.

    Regards,
    Petya
    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 Public Issue Tracking system and vote to affect the priority of the items
  4. James
    James avatar
    3 posts
    Registered:
    19 Nov 2013
    20 Nov 2013 in reply to Petya
    Link to this post
    Thank you, that works great now.
4 posts, 0 answered