public void OnGet(int Id) { TargetDirectory = m_documentManager.GetTargetDirectoryByID(Id); string[] filesindirectory = Directory.GetDirectories(TargetDirectory.DirectoryPath); FilePaths = filesindirectory.ToList(); Docs = m_context.DMS.ToList(); //for elke filepath kijken of deze al bestaat, anders toevoegen aan DB foreach (var item in FilePaths) { var newPath = Docs.Find(x => x.FilePath == item); if (newPath == null) { TargetDirectory.FilePaths.Add(new Models.DMS { FilePath = item, DocumentLevel = Models.DocumentLevel.Invisible }); //add new => document always invisible m_context.SaveChanges(); } else { //path already in DataBase => content will still be available } } Docs = TargetDirectory.FilePaths.ToList(); }