@@ -11,7 +11,7 @@ To support the new add-in model, the Office 365 Developer Patterns and Practices
11
11
12
12
- Create custom site templates by simply pointing at a site model.
13
13
- 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.
15
15
16
16
[ !INCLUDE [ pnp-provisioning-engine] ( ../../includes/snippets/open-source/pnp-provisioning-engine.md )]
17
17
@@ -83,7 +83,7 @@ To begin, we need to connect to the site that we wish to model as our provisioni
83
83
ProvisioningTemplate template = GetProvisioningTemplate (defaultForeground , templateWebUrl , userName , pwd );
84
84
85
85
// APPLY the template to new site from
86
- ApplyProvisioningTemplate (defaultForeground , targetWebUrl , userName , pwd , template );
86
+ ApplyProvisioningTemplate (targetWebUrl , userName , pwd , template );
87
87
88
88
// Pause and modify the UI to indicate that the operation is complete
89
89
Console .ForegroundColor = ConsoleColor .White ;
@@ -244,6 +244,42 @@ After we extract, save, and persist the provisioning template, the next and fina
244
244
web .ApplyProvisioningTemplate (template , ptai );
245
245
```
246
246
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
+ ```
247
283
## See also
248
284
249
285
- [PnP remote provisioning ](pnp - remote - provisioning .md )
0 commit comments