-
Notifications
You must be signed in to change notification settings - Fork 217
Description
Category
- Bug
Describe the bug
When creating folders in a SharePoint list using the PnP Core SDK, the created folders are not visible in the UI and don't have any associated metadata (ListItemAllFields is missing). This makes them effectively internal system folders that users can't interact with.
I tried both:
await list.RootFolder.EnsureFolderAsync(folderName);and
await list.RootFolder.Folders.AddAsync("MySubFolder");Both approaches result in folders being created in the root, but without metadata, and are not visible.
After digging a bit, I found that using the AddSubFolderUsingPath REST endpoint does properly create the folder with metadata:
var listServerRelativePath = $"{sitePath}/Lists/{listName}";
var folderUrl = $"_api/web/GetFolderByServerRelativePath(DecodedUrl='{Uri.EscapeDataString(listServerRelativePath)}')/AddSubFolderUsingPath(DecodedUrl='{Uri.EscapeDataString(folderName)}')";
var apiRequest = new ApiRequest(HttpMethod.Post, ApiRequestType.SPORest, folderUrl, "");
var response = await context.Web.ExecuteRequestAsync(apiRequest);This approach works as expected, and the folder is immediately visible in the list.
Steps to reproduce
- Use PnP Core SDK to target a SharePoint list
- Attempt to create a folder using
EnsureFolderAsyncorFolders.AddAsync - Check the UI, the folder isn't visible
- Inspect via REST API (
_api/Web/GetFolderByServerRelativePath('/sites/TestSite/Lists/ExampleList')/Folders), folder exists but has no metadata (ListItemAllFieldsis null)
Expected behavior
Folders created in SharePoint lists should include metadata and be visible to users, just like folders created through the SharePoint UI.
Environment details (development & target environment)
- SDK version: 1.15.0
- OS: Windows 11
- SDK used in: ASP.NET Core Web API
- Framework: .NET 9
- Browser(s): N/A
- Tooling: Visual Studio 2022
- Additional details: Auth handled via
Microsoft.Identity.WebandPnP.Core.Auth
Additional context
Would be great if the SDK could detect this scenario and handle it with the correct API call under the hood, or expose a helper method for proper list folder creation.
Has anyone else run into this before?