Skip to content

Issues with folder creation in lists #1680

@Jwaegebaert

Description

@Jwaegebaert

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

  1. Use PnP Core SDK to target a SharePoint list
  2. Attempt to create a folder using EnsureFolderAsync or Folders.AddAsync
  3. Check the UI, the folder isn't visible
  4. Inspect via REST API (_api/Web/GetFolderByServerRelativePath('/sites/TestSite/Lists/ExampleList')/Folders), folder exists but has no metadata (ListItemAllFields is 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.Web and PnP.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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions