EnsureFolderAsync troubles
See original GitHub issueCategory
- Bug
Describe the bug
I’m trying to use await folder.EnsureFolderAsync
to create nested folder on the fly before adding files in it.
File are not upload in the good folder.
Steps to reproduce
You can reproduce with this code.
I’m trying to upload in list with folder in it. /MyList/Daily/Today is working /MyList/Test/Test not working /MyList/Weekly/Test not working and file are in the second folder.
using var context = await _pnpContext.GetContextAsync();
var folder = (await context.Web.Lists.GetByIdAsync(libraryId, p => p.RootFolder)).RootFolder;
var suby = await folder.EnsureFolderAsync(CleanFolderName(folderName));
var subfolder = await context.Web.GetFolderByIdAsync(suby.UniqueId);
await folder.Files.AddAsync(fileName, stream);
private static string CleanFolderName(string folderName)
{
if (folderName.StartsWith("/"))
{
return folderName.Remove(0, 1);
}
return folderName;
}
the var suby always return /MyList/Test/Test.
Thank in advance for your help.
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (4 by maintainers)
Top Results From Across the Web
pnpcore/docs/using-the-sdk/folders-intro.md at dev
When adding folders a very convenient method to use is the EnsureFolderAsync method as this one can take a folder path and verify...
Read more >Is it possible to create a Document Set in library using ...
EnsureFolderAsync ("myNewFolder"); // load items for the document library var listWithItems = await list.GetAsync( p => p.Items, p => p.
Read more >rushstack/libraries/node-core-library/src/FileSystem.ts at main
Monorepo for tools developed by the Rush Stack community - rushstack/libraries/node-core-library/src/FileSystem.ts at main · microsoft/rushstack.
Read more >Sharepoint Integration (Extended) 2: Using PnP.Core
EnsureFolderAsync where EnsureFolder works like a GetOrCreate, so there are no problems if the folder is already present.
Read more >Untitled
... adding a new IFolder into an IFolderCollection by using the Add methods or using EnsureFolderAsync. ... WebbI realize that the problem is...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@jansenbe i try with the nightly release and it works as expected. 👍🏻 All my file are upload in the correct folder.
Thank a lot, you rock !!
@pINKmUNster : below approach adds the 3 files in the right folder:
Using your code however exposed an issue with the EnsureFolderAsync() method, it did not work when ran on an existing folder. I did not get the same behavior you saw, but adding multiple documents in the same folder failed due to this. I’ve just pushed a fix (https://github.com/pnp/pnpcore/commit/e1947c191e74189a7e9549779944a402da4bc948) for that, will be part of tomorrow’s nightly release.