Invoke-KFFileTemplate

Syntax

Invoke-KFFileTemplate
  -TemplateStream <System.IO.Stream-object>
  [-TemplateType] <template-type>
  [[-LocalConfig] <local-config>
  [-ToFile <path>]
  [-ToUrl <url>]
  [-ToBytes[$:false]]
  [-ToStream[$:false]]
  [-OverwriteIfExists[:$true]]
  [-ThrowResolveErrors[:$false]]
  [-ThrowErrors[:$true]]
Invoke-KFFileTemplate
  -TemplateBytes <bytes-array>
  [-TemplateType] <template-type>
  [[-LocalConfig] <local-config>
  [-ToFile <path>]
  [-ToUrl <url>]
  [-ToBytes[$:false]]
  [-ToStream[$:false]]
  [-OverwriteIfExists[:$true]]
  [-ThrowResolveErrors[:$false]]
  [-ThrowErrors[:$true]]
Invoke-KFFileTemplate
  -TemplateUrl <url>
  [-TemplateType] <template-type>
  [[-LocalConfig] <local-config>
  [-ToFile <path>]
  [-ToUrl <url>]
  [-ToBytes[$:false]]
  [-ToStream[$:false]]
  [-OverwriteIfExists[:$true]]
  [-ThrowResolveErrors[:$false]]
  [-ThrowErrors[:$true]]
Invoke-KFFileTemplate
  -TemplatePath <file-path>
  [-TemplateType] <template-type>
  [[-LocalConfig] <local-config>
  [-ToFile <path>]
  [-ToUrl <url>]
  [-ToBytes[$:false]]
  [-ToStream[$:false]]
  [-OverwriteIfExists[:$true]]
  [-ThrowResolveErrors[:$false]]
  [-ThrowErrors[:$true]]

Support

>= kenaflow 1.0.0

Return

String or Stream or Byte array or nothing.

Description

This Cmdlet can be used to process Microsoft Word or PowerPoint files that contain placeholders. They are replaced with content which comes from the workflow Config List or the current or per item specified list item, or from a local configuration object that can optionally be transferred with -LocalConfig.

Please read the article "Templates" for details.

When using -ThrowResolveErrors:$false you can suppress exceptions resulting from not existing placeholders.

The file template can

  • be a byte array
  • be a local file, e.g. in the workflow folder
  • be a System.IO.Stream
  • be a SharePoint located file

The result file can

  • be written as local file, e.g. in the workflow folder
  • be written to a SharePoint library (in case of SharePoint workflows)
  • be returned as Byte array
  • be returned as System.IO.Stream

If multiple return parameters are specify only one is used, in this order (the first that comes is served):

  • -ToFile
  • -ToStream
  • -ToBytes
  • -ToUrl

Parameters

-TemplateStream <System.IO.Stream-object>

The input template is a stream.

-TemplateUrl <url>

The input template is a SharePoint located file. Only available for SharePoint workflows.

-TemplatePath <file-path>

The input template is a file in the file system, e.g. in the workflow folder.

-TemplateBytes <bytes-array>

The input template as byte array.

[-TemplateType] <template-type>

The type of the template file

  • Word or
  • PowerPoint

`[[-LocalConfig] ]

The "local config" object that can be used to pass in data as Hashtable to replace placesholders of the format ((xxx)). This is optional.

`[-Item ]

In case of SharePoint workflow you can specify a list item here. In case of list and state machine workflow the currently processed item is used by default.

[-ToFile <path>]

Writes the result to a local file.

[-ToUrl <url>]

Writes the result to a SharePoint library. Only available for SharePoint workflows.

[-ToBytes[$:false]]

Returns the result as byte array.

[-ToStream[$:false]]

Returns the result as stream.

[-OverwriteIfExists[:$true]]

Can be used not to overwrite the result by specifying -OverwriteIfExists:$false

[-ThrowResolveErrors[:$false]]

Templates normally contain placeholders. Sometimes they are missing or there is an error while replacing the placeholder. In this case and without this parameter an exception is thrown and the script maybe stops. If you specify this parameter the missing or wrong interpreted placeholders are ignored. !This could lead to format or content errors!

[-ThrowErrors[:$true]]

Examples

$item = Get-PnpListItem -List "Custom List" -Id 1
Invoke-KFTemplate "<html><body><span>{{Author}}</span></body></html>" -Item $item -ThrowResolveErrors:$false

Discussion