Spfx Extension Move document
-
16-02-2021 - |
Question
Hi i am trying below code to move document from Documents library to SiteAssets library , but how to make it dynamic so selected document will be move to destination library
@override
public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
const destinationUrl = `/sites/test/SiteAssets/new-file.docx`;
switch (event.itemId) {
case 'COMMAND_1':
sp.web.getFileByServerRelativePath("/sites/test/Documents/test.docx").moveTo(destinationUrl);
break;
case 'COMMAND_2':
// Dialog.alert(`${this.properties.sampleTextTwo}`);
break;
default:
throw new Error('Unknown command');
}
}
Solution
you need to get the selected items in library. You can obtain those by using event.selectedRows
. The code should look like below
@override
public onExecute(event: IListViewCommandSetExecuteEventParameters): void {
switch (event.commandId) {
case 'COMMAND_1':
// Check if the user selected some items
if (event.selectedRows.length > 0) {
// Check the selected rows
event.selectedRows.forEach((row: RowAccessor, index: number) => {
//Add the code to move files
});
}
break;
default:
throw new Error('Unknown command');
}
}
Licensed under: CC-BY-SA with attribution
Not affiliated with sharepoint.stackexchange