Let’s assume that we have a document library with a deep folder structure. Sometimes it’s very hard and time consuming to locate documents under those folders.
Is there a way to display all files as a flat list without folders? It’s very simple, we only need to do some modifications to the view
If we have to automate the behavior, we can use either C# or PowerShell to do the needful. In both cases we need to update SPView.Scope property.
C#
- var viewCollection = newDocLib.Views;
- const string viewName = "File List";
- var viewFields = new StringCollection
- { "Type", "LinkFilename", "Modified", "Editor" };
- var filesOnlyView = viewCollection.Add(viewName, viewFields, string.Empty, 5, true, false);
- filesOnlyView.Scope = SPViewScope.Recursive;
- filesOnlyView.Update();
- newDocLib.Update();
PowerShell
Following script will create the view for all document libraries in all site collections within a specific web application
- Get-SPSite -WebApplication "http://sp13:8080" -limit All | ForEach-Object {
- foreach ($w in $_.AllWebs){
- foreach($docLib in $w.Lists | where {$_.BaseTemplate -eq "DocumentLibrary"})
- {
- #create list view
- $viewCollection = $docLib.Views
- $viewName = "File List"
- $fields = $docLib.Views["All Documents"].ViewFields.ToStringCollection()
- $itemOnlyView = $docLib.Views.Add($viewName, $fields,"", 30, $True, $False)
- $itemOnlyView.Scope = "Recursive"
- $itemOnlyView.Update()
- $docLib.Update()
- }
- }
- }
This will create a new view called “File List” which displays all files in the library without folders
No comments:
Post a Comment