Comments (6)
Hi Michał,
First of all, thanks for using the lib!
I can see some probable issues related to incorrect usage of getFolderByServerRelativePath
.
getFolderByServerRelativePath
expects relative path without webServerRelativeUrl
part and without /
in the beginning.
In some cases, it can be handy using getFolderByServerRelativeUrl
.
Then, folder name can't be updated like this, you got to get folder's item and update FileLeafRef
property. This is REST API related nuances so they can be omitted in PnPjs's docs.
Here is the example that should make all clear:
/**
* Where `/sites/site` is a `webServerRelativeUrl`
*/
// const folder = pnp.sp.web.getFolderByServerRelativeUrl('/sites/site/DocLib/Folder1');
const folder = pnp.sp.web.getFolderByServerRelativePath('DocLib/Folder1'); // equivalent
folder.getItem()
.then(item => item.update({ FileLeafRef: 'Folder2' }))
.then(console.log);
from pnpjs.
@koltyakov
After doing some research and sniffing requests being sent by SharePoint's browser interface, I found out the way to run SP.MoveCopyUtil
with REST API!
Here is the code:
const spLib = require('./node_modules/@pnp/sp')
const spHttp = new spLib.SPHttpClient()
await spHttp.fetch(
`https://test.sharepoint.com/sites/APP/_api/SP.MoveCopyUtil.MoveFolderByPath()`,
{
method: 'POST',
body: JSON.stringify({
srcPath: {
__metadata: {type: 'SP.ResourcePath'},
DecodedUrl:
'https://test.sharepoint.com/path/to/your/folder/here/1',
},
destPath: {
__metadata: {type: 'SP.ResourcePath'},
DecodedUrl:
'https://test.sharepoint.com/path/to/your/folder/here/2',
},
}),
headers: {
accept: 'application/json;odata=verbose',
'content-type': 'application/json;odata=verbose',
},
}
)
I think it would be great if we had a helper function available, something like sp.moveCopyUtil.moveFolderByPath
.
from pnpjs.
Thanks! SP.MoveCopyUtil
sounds to be a nice asset to add in terms where it's the only option.
from pnpjs.
@koltyakov
Thank you very much!
Three supplementary questions:
- You mentioned differences between
getFolderByServerRelativePath
andgetFolderByServerRelativeUrl
. I haven't noticed them before becausegetFolderByServerRelativePath
works for both absolute and relative paths. Is it an excepted behavior? - Is there a property which defines the parent directory, so I can move my folder somewhere else (i.e.
DocLib/Folder1/moveme
->DocLib/Folder2/moveme
)? Basing on the only place in SharePoint documentation where FileLeafRef is mentioned I tried to setParentFolderId
with GUID of desired parent, but got 400 Bad Request error. Same withParentID
,ParentItemID
andFileDirRef
. - Mostly related to no. 2: is there a method to list all properties of an item? Neither
get()
norgetItem()
give information about existence ofFileLeafRef
, so it's a bit tricky, especially when documentation sample usesName
property.
from pnpjs.
I haven't noticed them before because getFolderByServerRelativePath works for both absolute and relative paths. Is it an excepted behavior?
Oh, that is true. I missed this. Sorry. Only used getFolderByServerRelativePath
with paths like in the example above. And yes it resolves both types of paths. Thank you! Never stop learning something new.
Is there a property which defines the parent directory, so I can move my folder somewhere else
If a parent folder exists, FileLeafRef
can include it, and the folder will be moved.
const folder = pnp.sp.web.getFolderByServerRelativePath('DocLib/Folder3');
folder.getItem()
.then(item => item.update({ FileLeafRef: 'Folder2/Folder3' }))
.then(console.log);
Yet, can't find a way of moving folder on a level above existing (i.e. /sites/site/DocLib/Folder2/Folder4 -> /sites/dev-a/DocLib1/Folder4). And have a feeling that it's not possible in REST and JSOM's SP.MoveCopyUtil should be used as a workaround.
Mostly related to no. 2: is there a method to list all properties of an item?
These props are requestable only via strict direct definition in $select.
Good question how to get all the options. I use a knowledge of other object models and some techniques (e.i. folder.listItemAllFields.select('FieldValuesAsText').expand('FieldValuesAsText').get().then(console.log)
or getting entities.
from pnpjs.
This issue is locked for inactivity or age. If you have a related issue please open a new issue and reference this one. Closed issues are not tracked.
from pnpjs.
Related Issues (20)
- Is there any alternative to store large amount of data in Multiline Text column? HOT 3
- How to get spContext in PCF component using PnPJS + MSAL (needed for ModernTaxonomyPicker) HOT 3
- Error while importing PnP js in Node (CommonJS) application HOT 9
- Property 'web' does not exist on type 'SPFI'. HOT 4
- Getting TypeError: Cannot read properties of undefined (reading 'aadTokenProviderFactory') when using sp pnp graph HOT 3
- Need help in understanding the Sharepoint Patterns and Policies. HOT 5
- Help insert Managed Metadata Data into a multivalue field HOT 3
- gettoken for another Azure APP using client id and pnpjs authenticated instance HOT 5
- SPFx Context supplied to SPFx Behavior is null or undefined HOT 2
- Parsing verbose JSON HOT 2
- Adding Excel workbook support HOT 3
- TypeError: Failed to fetch at c when trying to attach files in SPFx HOT 6
- @pnp/graph - spfx msal v3 single sign on redirect HOT 5
- copyByPath can return an unuseable object HOT 6
- Async Iterator Pattern Type Error HOT 3
- Getfilebyserverrelativeurl return corrupted file for .docx file HOT 3
- Batching multiple lists fail HOT 4
- Custom Http request to pull RateLimit-Reset header HOT 3
- Why use the .js extension in imports? HOT 3
- Email Notification delays while send email using @pnp/sp/utilities HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from pnpjs.