Skip to content

Commit

Permalink
Merge pull request #3080 from juliemturner/version-4
Browse files Browse the repository at this point in the history
Documentation Updates
  • Loading branch information
juliemturner authored Jul 8, 2024
2 parents 61df3d1 + 2a923b8 commit 0967a15
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 17 deletions.
4 changes: 4 additions & 0 deletions docs/getting-started.md
Original file line number Diff line number Diff line change
Expand Up @@ -415,6 +415,10 @@ The new factory function allows you to create a connection to a different web ma
const web = Web([sp.web, {Other Web URL}]);
```

## Multi-Geo / Cross tenant calls in SharePoint Framework (SPFx)

If you are working in a multi-geo tenant or trying to work across tenants (essentially the same thing) then the [normal configuration](#using-pnpsp-spfi-factory-interface-in-spfx) in SPFx will not work. To connect cross tenants in the browser you will need to us the [@pnp/msaljsclient](./msaljsclient/index.md) to make the connection to the other tenant or geo.

## Next Steps

For more complicated authentication scenarios please [review the article describing all of the available authentication methods](./concepts/authentication.md).
61 changes: 45 additions & 16 deletions docs/sp/folders.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,15 @@ import { folderFromServerRelativePath } from "@pnp/sp/folders";

const sp = spfi(...);

// URL CANNOT BE ENCODED, URL CANNOT END IN "/"
const url = "/sites/dev/documents/folder4";

// file is an IFile and supports all the file operations
const folder = folderFromServerRelativePath(sp.web, url);
// folder is an IFolder and supports all the folder operations
const folder: IFolder = folderFromServerRelativePath(sp.web, url);

// for example
const folderInfo = await folder();
const files = await folder.files();
```

### folderFromAbsolutePath
Expand All @@ -65,11 +70,13 @@ const sp = spfi(...);

const url = "https://tenant.sharepoint.com/sites/dev/documents/folder";

// file is an IFile and supports all the file operations
const folder = folderFromAbsolutePath(sp.web, url);
// folder is an IFolder and supports all the folder operations
// Unlike folderFromServerRelativePath, this method must be await'd to resolve folder from absolute Url.
const folder: IFolder = await folderFromAbsolutePath(sp.web, url);

// for example
const folderInfo = await folder();
const files = await folder.files();
```

### folderFromPath
Expand All @@ -89,15 +96,15 @@ const sp = spfi(...);

const url = "https://tenant.sharepoint.com/sites/dev/documents/folder";

// file is an IFile and supports all the file operations
// folder is an IFolder and supports all the folder operations
const folder = folderFromPath(sp.web, url);

// for example
const folderInfo = await folder();

const url2 = "/sites/dev/documents/folder";

// file is an IFile and supports all the file operations
// folder is an IFolder and supports all the folder operations
const folder2 = folderFromPath(sp.web, url2);

// for example
Expand All @@ -115,13 +122,18 @@ import "@pnp/sp/folders";

const sp = spfi(...);

// creates a new folder for web with specified url
const folderAddResult = await sp.web.folders.addUsingPath("folder url");
// URL CANNOT BE ENCODED
const url = "/sites/dev/Shared Documents/MyFolder"

// creates a new folder for web with specified server relative url
const folderAddResult = await sp.web.folders.addUsingPath(url);
```

### getByUrl

Gets a folder instance from a collection by folder's name
Gets a folder instance from a collection by folder's name.
This call is the equivalent of getting the document libraries root folder.
e.g. `const listFolders = await sp.web.lists.getByTitle("Documents").rootFolder();`

```TypeScript
import { spfi } from "@pnp/sp";
Expand All @@ -130,7 +142,8 @@ import "@pnp/sp/folders";

const sp = spfi(...);

const folder = await sp.web.folders.getByUrl("folder name")();
// pass the name of the document library, cannot include relative paths for subfolders.
const folder = await sp.web.folders.getByUrl("Shared Documents")();
```

## IFolder
Expand Down Expand Up @@ -187,10 +200,13 @@ import "@pnp/sp/folders";

const sp = spfi(...);

const metrics = await sp.web.getFolderByServerRelativePath("/sites/dev/shared documents/target").storageMetrics();
// URL CANNOT BE ENCODED
const url = "/sites/dev/shared documents/target";

const metrics = await sp.web.getFolderByServerRelativePath(url).storageMetrics();

// you can also select specific metrics if desired:
const metrics2 = await sp.web.getFolderByServerRelativePath("/sites/dev/shared documents/target").storageMetrics.select("TotalSize")();
const metrics2 = await sp.web.getFolderByServerRelativePath(url).storageMetrics.select("TotalSize")();
```

### move by path
Expand All @@ -206,6 +222,7 @@ import "@pnp/sp/folders";

const sp = spfi(...);

// URL CANNOT BE ENCODED - will get "Access is denied" error.
// destination is a server-relative url of a new folder
const destinationUrl = `/sites/my-site/SiteAssets/new-folder`;

Expand All @@ -223,6 +240,7 @@ import "@pnp/sp/folders";

const sp = spfi(...);

// URL CANNOT BE ENCODED - will get "Access is denied" error.
// destination is a server-relative url of a new file
const destinationUrl = `/sites/dev2/SiteAssets/folder`;

Expand All @@ -244,6 +262,7 @@ import "@pnp/sp/folders";

const sp = spfi(...);

// URL CANNOT BE ENCODED - will get "Access is denied" error.
// destination is a server-relative url of a new folder
const destinationUrl = `/sites/my-site/SiteAssets/new-folder`;

Expand All @@ -261,6 +280,7 @@ import "@pnp/sp/folders";

const sp = spfi(...);

// URL CANNOT BE ENCODED - will get "Access is denied" error.
// destination is a server-relative url of a new file
const destinationUrl = `/sites/dev2/SiteAssets/folder`;

Expand All @@ -282,7 +302,7 @@ import "@pnp/sp/folders";

const sp = spfi(...);

await sp.web.rootFolder.folders.getByUrl("My Folder").delete();
await sp.web.rootFolder.folders.getByUrl("Shared Documents").delete();
```

### delete with params
Expand All @@ -296,7 +316,7 @@ import "@pnp/sp/folders";

const sp = spfi(...);

await sp.web.rootFolder.folders.getByUrl("My Folder").deleteWithParams({
await sp.web.rootFolder.folders.getByUrl("Shared Documents").deleteWithParams({
BypassSharedLock: true,
DeleteIfEmpty: true,
});
Expand All @@ -313,7 +333,7 @@ import "@pnp/sp/folders";

const sp = spfi(...);

await sp.web.rootFolder.folders.getByUrl("My Folder").recycle();
await sp.web.rootFolder.folders.getByUrl("Shared Documents").recycle();
```

### serverRelativeUrl
Expand Down Expand Up @@ -386,6 +406,7 @@ import "@pnp/sp/files/folder";

const sp = spfi(...);

// URL CANNOT BE ENCODED
const files = await sp.web.getFolderByServerRelativePath("Shared Documents").files();
```

Expand All @@ -400,6 +421,7 @@ import "@pnp/sp/folders";

const sp = spfi(...);

// URL CANNOT BE ENCODED
const itemFields = await sp.web.getFolderByServerRelativePath("Shared Documents/My Folder").listItemAllFields();
```

Expand All @@ -414,6 +436,7 @@ import "@pnp/sp/folders";

const sp = spfi(...);

// URL CANNOT BE ENCODED
const parentFolder = await sp.web.getFolderByServerRelativePath("Shared Documents/My Folder").parentFolder();
```

Expand All @@ -428,6 +451,7 @@ import "@pnp/sp/folders";

const sp = spfi(...);

// URL CANNOT BE ENCODED
const properties = await sp.web.getFolderByServerRelativePath("Shared Documents/Folder2").properties();
```

Expand All @@ -442,6 +466,7 @@ import "@pnp/sp/folders";

const sp = spfi(...);

// URL CANNOT BE ENCODED
const contentTypeOrder = await sp.web.getFolderByServerRelativePath("Shared Documents/Folder2").select('uniqueContentTypeOrder')();
```

Expand All @@ -456,6 +481,7 @@ import "@pnp/sp/folders";

const sp = spfi(...);

// URL CANNOT BE ENCODED
const folder = sp.web.getFolderByServerRelativePath("Shared Documents/My Folder");

const item = await folder.getItem();
Expand All @@ -475,6 +501,7 @@ import "@pnp/sp/lists";

const sp = spfi(...);

// URL CANNOT BE ENCODED
const newFolderResult = await sp.web.rootFolder.folders.getByUrl("Shared Documents").folders.addUsingPath("My New Folder");
const item = await sp.web.rootFolder.folders.getByUrl("Shared Documents").folders.getByUrl(newFolderResult.Name).listItemAllFields();

Expand All @@ -497,8 +524,10 @@ import { IFolder } from "@pnp/sp/folders";

const sp = spfi(...);

// URL CANNOT BE ENCODED and cannot include sub-paths.
const url = "Folder Name";
// add a folder to site assets
const folder: IFolder = await sp.web.rootFolder.folders.getByUrl("SiteAssets").addSubFolderUsingPath("folder name");
const folder: IFolder = await sp.web.rootFolder.folders.getByUrl("SiteAssets").addSubFolderUsingPath(url);
```

### getFolderById
Expand Down
2 changes: 1 addition & 1 deletion docs/sp/items.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ console.log(items2);

### Get Paged Items

Working with paging can be a challenge as it is based on skip tokens and item ids, something that is hard to guess at runtime. To simplify things you can use the Async Iterator functionality on the Items class to assist. For advanced paging techniques using the Async Iterator, please review [Async Paging]('/concepts/async-paging.md')
Working with paging can be a challenge as it is based on skip tokens and item ids, something that is hard to guess at runtime. To simplify things you can use the Async Iterator functionality on the Items class to assist. For advanced paging techniques using the Async Iterator, please review [Async Paging]('../concepts/async-paging.md')

```TypeScript
import { spfi } from "@pnp/sp";
Expand Down

0 comments on commit 0967a15

Please sign in to comment.