Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enumerating child objects of document library folder shows parent objects with AsRequested #1586

Open
1 task done
ianleeder opened this issue Nov 29, 2024 · 0 comments
Open
1 task done

Comments

@ianleeder
Copy link

Category

  • Bug

Describe the bug

If I have a folder inside a document library in SharePoint, and enumerate the child objects (files or folders) of that folder, using .AsRequested(), it returns objects of the root folder, not the specified folder.

I have a SharePoint document library named "SDK Test" with the following structure:

Top-level file.txt
Top-level Folder\
    Nested file.txt
    Nested Folder\

image

If I enumerate the Files or Folders on the document library (using the RootFolder as shown in documentation), it works correctly and returns the same results whether or not I include the .AsRequested().

However if I get a reference to the document folder ("Top-level Folder") and enumerate its children, I get different results if I use .AsRequested(): it shows the top-level files/folders.

The comments on AsRequested() indicate it simply uses previously-loaded data to prevent another round-trip to SharePoint:

// We're using AsRequested() to query the already loaded domain models, if not a new query would 
// issued to load the lists

As such I can see that .AsRequested may have the capability to return cached data if called first, but:

  1. I'm calling .Files directly before calling .AsRequested()
  2. It's returning data from the parent document library, not the specified folder.

Also the order of calling .Files or .Files.AsRequested() doesn't matter.

Steps to reproduce

This code can be used to replicate the issue:

public async Task TestSdk()
{
    using PnPContext context = _pnpContextFactory.Create("Default");

    IFolder libraryFolder = (await context.Web.Lists.GetByTitleAsync("SDK Test", p => p.RootFolder)).RootFolder;
    await libraryFolder.LoadAsync(p => p.Folders, p => p.Files);
    Console.WriteLine("Library Folder");
    Console.WriteLine("--------------");
    PrintDebug(libraryFolder);

    Console.WriteLine();

    IFolder topLevelFolder = libraryFolder.Folders.FirstOrDefault(p => p.Name == "Top-level Folder")!;
    await topLevelFolder.LoadAsync(p => p.Folders, p => p.Files);
    Console.WriteLine("Top-level Folder");
    Console.WriteLine("----------------");
    PrintDebug(topLevelFolder);
}

public void PrintDebug(IFolder folder)
{
    foreach (var f in folder.Folders)
    {
        Console.WriteLine($"Folders: {f.Name}");
    }
    foreach (var f in folder.Folders.AsRequested())
    {
        Console.WriteLine($"Folders AsRequested: {f.Name}");
    }
    foreach (var f in folder.Files)
    {
        Console.WriteLine($"Files: {f.Name}");
    }
    foreach (var f in folder.Files.AsRequested())
    {
        Console.WriteLine($"Files AsRequested: {f.Name}");
    }
}

And this is the output:

Library Folder
--------------
Folders: Top-level Folder
Folders: Forms
Folders AsRequested: Top-level Folder
Folders AsRequested: Forms
Files: Top-level file.txt
Files AsRequested: Top-level file.txt

Top-level Folder
----------------
Folders: Nested Folder
Folders AsRequested: Top-level Folder     <-- Wrong
Folders AsRequested: Forms                <-- Wrong
Files: Nested file.txt
Files AsRequested: Top-level file.txt     <-- Wrong

Expected behavior

AsRequested() can return cached or old for the specified folder ("Top-level folder"), but it should not be returning data for the library ("SDK Test").

Environment details (development & target environment)

  • SDK version: 1.14.0
  • OS: Docker devcontainer mcr.microsoft.com/devcontainers/dotnet:8.0 based on Debian 12.7
  • SDK used in: Class library accessed by a Console App.
  • Framework: .NET Core 8.0.403
  • Browser(s): N/A
  • Tooling: VS Code
  • Additional details: N/A
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant