Document library displaying all documents

Posted by Community Admin on 04-Aug-2018 16:23

Document library displaying all documents

All Replies

Posted by Community Admin on 19-Nov-2013 00:00

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

Posted by Community Admin on 19-Nov-2013 00:00

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

Posted by Community Admin on 20-Nov-2013 00:00

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

Posted by Community Admin on 20-Nov-2013 00:00

Thank you, that works great now.

This thread is closed