0

I am creating a folder inside a List with the following code:

TypeScript
import {sp} from "@pnp/sp";

const shpList = sp.site.rootWeb.lists.getById(ListId);

shpList.items.add(
{
  Title: folderName,
  FileSystemObjectType: 1,
  ContentTypeId: '0x0120',
  FileLeafRef: folderName,
  DisplayName: folderName
} )

And it does create the folder, but the navigation displays 130_.000 as the folder. (It's the item's ID plus underscore, dot and three zeros)

Is there a way to create the item so it uses the title as the navigation?

Is there any place I can look for the default properties of SharePoint?


Here a list of the properties I have already tested:

  • Name (and name) | value: folderName | result: error (not registered property)
  • FileRef | value: folderName | result: Does not seem to do anything
  • Path (and path) | value: folderName | result: error (not registered property)
  • Folder | value: folderName | result: error (primitive value not null)
  • Url (& url & URL) | value: folderName | result: error (not registered property)
  • Have you tried setting Name property?? – Ganesh Sanap Jun 5 at 13:08
  • yep, I guess I will list all the properties that I already tested. – the simple Jun 5 at 13:10
  • Ok. Add all the approaches you tried. that will be helpful to understand and answer your question. – Ganesh Sanap Jun 5 at 13:11
  • I Have tried creating folder using '__metadata': { 'type': 'SP.Data.ListInternalNameListItem' }, "Title": "Folder 10", "FileLeafRef": "Folder 10", // No effect here "FileSystemObjectType": 1, "ContentTypeId":"0x0120". And it is creating folders correctly. – Ganesh Sanap Jun 5 at 13:28
  • When you access the folder in the list, does the navigation bar displays listName > folderName? In my case it displays listName > id_.000, but when I create the folder manually it does display the folderName. – the simple Jun 5 at 13:37
0

What worked for me is creating the folder then updating it with the right FileLeafRef like so:

let newFolder = {
        ContentTypeId: '0x0120',
        Title: folderName
      };


  shpList.items.add( newFolder )
          .then((value) =>
          {
            shpList.items.getById( value.data.Id )
            .update({FileLeafRef: folderName})
            .then(() =>
            {
              // The folder is not created as intented
            }
          } );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.