Error - Cannot read properties of undefined (reading 'id') while adding custom file picker property to custom webpart

kem104 170 Reputation points
2024-03-13T14:52:28.89+00:00

I am getting following error , while adding the file picker property to my Custom webpart.

First time I am creating custom webpart with file picker property so I get some reference from this site - PropertyFieldFilePicker - @pnp/spfx-property-controls. I did exactly same this which is in that article and getting the error.

Could anyone please help me to find out where I make some mistake? here I also share some code for reference.

anyone help will be appreciated.

User's image

Code for reference

User's image

User's image

Microsoft 365 and Office SharePoint Development
Microsoft 365 and Office SharePoint For business Windows
Microsoft 365 and Office SharePoint Server Development
0 comments No comments
{count} votes

Accepted answer
  1. RaytheonXie_MSFT 40,471 Reputation points Microsoft External Staff
    2024-03-14T07:13:04.69+00:00

    Hi @kem104,

    You could check the steps to instsall file picker. First run this command to install the controls.

    npm install @pnp/spfx-property-controls
    

    Add this to your main webpart code.

    import { PropertyFieldFilePicker, IPropertyFieldFilePickerProps, IFilePickerResult } from "@pnp/spfx-property-controls/lib/PropertyFieldFilePicker";
    

    Add a new property to your web part interface props.

    filePickerResult: IFilePickerResult;
    

    Then add into the getPropertyPaneConfiguration() function in your webpart under groupFields.

    PropertyFieldFilePicker('filePicker', {
          context: this.context,
          filePickerResult: this.properties.filePickerResult,
          properties: this.properties,
          onSave: (e: IFilePickerResult) => {
               console.log(e);
               this.properties.filePickerResult = e;
          },
          onChanged: (e: IFilePickerResult) => {
               console.log(e);
               this.properties.filePickerResult = e;
          },
          key: "filePickerId",
          buttonLabel: "File Picker",
          label: "File Picker"
     })
    
    
    

    Please refer to the following document


    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.