question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to add folder to SharePoint document library?

See original GitHub issue

Category

  • Bug

Describe the bug

[2020-10-14T06:39:35.203] Error while processing change
[2020-10-14T06:39:35.204] PnP.Core: Unresolved tokens found in API call https://{tenant}.sharepoint.com/sites/{sitecollection}/_api/Web/getFolderById('{Parent.Id}')/Folders/Add('2020-10sdfs').

Steps to reproduce

public async Task<string> EnsureFolder(string folderName)
{
    _logger.LogInformation($"Creating folder={folderName}");
    using (var ctx = await _pnpContextFactory.CreateAsync(new Uri(_absSiteUrl)))
    {
        var list = await ctx.Web.Lists.GetByTitleAsync("Site Pages");
        var folder = await list.RootFolder.AddFolderAsync(folderName + "sdfs");
        return folder.ServerRelativeUrl;
    }
}

Expected behavior

The new folder should be created.

Environment details (development & target environment)

  • SDK version: 0.3.11.0
  • OS: Windows
  • SDK used in: Azure Function
  • Framework: .NET Core v3.x
  • Tooling: Visual Studio 2019
  • Additional details:

Thanks for your contribution! Sharing is caring.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
piteeruscommented, Oct 15, 2020

This one works for me:

using (var ctx = await _pnpContextFactory.CreateAsync(new Uri(_absSiteUrl)))
{
	var list = await ctx.Web.Lists.GetByTitleAsync("Site Pages");
	var rootFolder = await list.RootFolder.GetAsync();
	var folder = await rootFolder.AddFolderAsync(folderName);
	return folder.ServerRelativeUrl;
}
1reaction
ypcodecommented, Oct 14, 2020

Hello @piteerus,

Thanks for reporting this, I think we may probably address that issue making sure the RootFolder is properly loaded and initialized in the AddFolderAsync method. We’ll need to think about the best way to handle it ( cc @jansenbe ).

[EDIT] After double-checking with Bert, it indeed looks like this one I mentioned is neither working… We will think about it and most likely address that issue.

The following snippet is from our passing unit test

IFolder parentFolder = await context.Web.Lists.GetByTitle("Documents").RootFolder.GetAsync();
IFolder newFolder = await parentFolder.AddFolderAsync("TEST");

It’s a bit less fluent style…, but this one works

Again, thanks for trying out the PnP Core SDK !

Regards, Yannick

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Create a Folder in SharePoint
In the document library where you want to create a folder, click on the + New dropdown button and select Folder from the...
Read more >
SharePoint: How to Add a Folder
Launch the SharePoint site where you wish to add the new folder, then open the “Document Library.” · From the menu, select “+...
Read more >
How to Create Folders in SharePoint: A Visual Guide
On the menu bar, select + New, and then select Folder. After naming and creating the folder, click on the ellipsis (…) next...
Read more >
Solved: How to Create a Folder in SharePoint in 2023
Step 2: Head to the Communication Site and go to the document library. Then, press the New button to select Folder on the...
Read more >
SharePoint: How to Add a New Folder to a Document Library
In the Ribbon, click the Files tab, and then click New Folder. In the New Folder dialog box, type a folder name in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found