Question Exclude Hidden Folders From SharePoint Search

tekut

New member
Joined
Jul 6, 2022
Messages
1
Programming Experience
1-3
Hi,

Below is my code to extract folders from sharepoint, but I also get de hidden folders like Form etc.
how can I fix this problem?

VB.NET:
Dim mappen As Folder = web.GetFolderByServerRelativeUrl(pad)

context.Load(mappen, Function(f2) f2.Folders)

context.ExecuteQuery()

For Each map As Microsoft.SharePoint.Client.Folder In mappen.Folders

     item = New ListViewItem(map.Name, 1)

     ListView1.Items.Add(item)

Next map
 
Firstly, please provide a meaningful title for all threads. It should provide a summary of the issue so we know what's relevant to us without having to open everything. I have fixed it for you on this occasion.
 
As for the issue, that Folder class has no dedicated property to indicate whether it's hidden but it does have a Properties property, so I would guess that there's something in there. That PropertyValues object has a FieldValues property that is type Dictionary(Of String, Object), so you can interrogate that to see whether it contains something useful. I'd start by adding something like this to your loop:
VB.NET:
Console.WriteLine(String.Join(", ", map.Properties.FieldValues.Keys.Cast(Of String)()))
That will tell you what property values are available for each Folder object and you should be able to pick out the relevant one if it's there. Assuming that there is one named "Hidden", you could then do this:
VB.NET:
If Not CBool(map.Properties.FieldValues("Hidden")) Then
     item = New ListViewItem(map.Name, 1)

     ListView1.Items.Add(item)
End If
or this:
VB.NET:
For Each map In mappen.Folders.
                       Cast(Of Microsoft.SharePoint.Client.Folder)().
                       Where(Function(f) Not CBool(f.Properties.FieldValues("Hidden")))
 
Back
Top