Skip to content

Commit 1627df5

Browse files
Merge pull request SharePoint#6358 from ahollandusc/master
Added paragraph and code block for ApplyProvisioningTemplate() function implementation
2 parents 1c34d28 + a286c1f commit 1627df5

File tree

1 file changed

+39
-3
lines changed

1 file changed

+39
-3
lines changed

docs/solution-guidance/provisioning-console-application-sample.md

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
title: Provisioning console application sample
33
description: Learn the fundamentals of using the PnP provisioning engine to create and persist, and then apply provisioning templates to new SharePoint site collections.
4-
ms.date: 06/05/2020
4+
ms.date: 10/09/2020
55
localization_priority: Priority
66
---
77

@@ -11,7 +11,7 @@ To support the new add-in model, the Office 365 Developer Patterns and Practices
1111

1212
- Create custom site templates by simply pointing at a site model.
1313
- Persist the model as a provisioning template.
14-
- Apply the custom template to new or existing site collections as needed.
14+
- Apply the custom template to existing site collections as needed.
1515

1616
[!INCLUDE [pnp-provisioning-engine](../../includes/snippets/open-source/pnp-provisioning-engine.md)]
1717

@@ -83,7 +83,7 @@ To begin, we need to connect to the site that we wish to model as our provisioni
8383
ProvisioningTemplate template = GetProvisioningTemplate(defaultForeground, templateWebUrl, userName, pwd);
8484

8585
// APPLY the template to new site from
86-
ApplyProvisioningTemplate(defaultForeground, targetWebUrl, userName, pwd, template);
86+
ApplyProvisioningTemplate(targetWebUrl, userName, pwd, template);
8787

8888
// Pause and modify the UI to indicate that the operation is complete
8989
Console.ForegroundColor = ConsoleColor.White;
@@ -244,6 +244,42 @@ After we extract, save, and persist the provisioning template, the next and fina
244244
web.ApplyProvisioningTemplate(template, ptai);
245245
```
246246

247+
1. The whole `ApplyProvisioningTemplate()` method implementation is below.
248+
249+
```csharp
250+
private static void ApplyProvisioningTemplate(string targetWebUrl, string userName, SecureString pwd, ProvisioningTemplate template)
251+
{
252+
using (var ctx = new ClientContext(targetWebUrl))
253+
{
254+
// ctx.Credentials = new NetworkCredentials(userName, pwd);
255+
ctx.Credentials = new SharePointOnlineCredentials(userName, pwd);
256+
ctx.RequestTimeout = Timeout.Infinite;
257+
258+
Web web = ctx.Web;
259+
260+
ProvisioningTemplateApplyingInformation ptai = new ProvisioningTemplateApplyingInformation();
261+
ptai.ProgressDelegate = delegate (String message, Int32 progress, Int32 total)
262+
{
263+
Console.WriteLine("{0:00}/{1:00} - {2}", progress, total, message);
264+
};
265+
266+
// Associate file connector for assets
267+
FileSystemConnector connector = new FileSystemConnector(@"c:\temp\pnpprovisioningdemo", "");
268+
template.Connector = connector;
269+
270+
// Because the template is actual object, we can modify this using code as needed
271+
template.Lists.Add(new ListInstance()
272+
{
273+
Title = "PnP Sample Contacts",
274+
Url = "lists/PnPContacts",
275+
TemplateType = (Int32)ListTemplateType.Contacts,
276+
EnableAttachments = true
277+
});
278+
279+
web.ApplyProvisioningTemplate(template, ptai);
280+
}
281+
}
282+
```
247283
## See also
248284

249285
- [PnP remote provisioning](pnp-remote-provisioning.md)

0 commit comments

Comments
 (0)