Document library displaying all documents
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();
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
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);
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();
Thank you, that works great now.