Interface IRendersZptFile
An entry-point object for use by consuming logic. Renders ZPT documents from a filesystem file and returns the rendered document as a stream.
Namespace: ZptSharp
Assembly: ZptSharp.Abstractions.dll
Syntax
public interface IRendersZptFile
Remarks
Use this interface in your own application if you want to render ZPT documents from source files which can be described by file paths. The RenderAsync(String, Object, RenderingConfig, CancellationToken) method will use the filename/extension to detect which document provider is appropriate for the file and automatically select from those which have been registered.
Methods
| Improve this Doc View SourceRenderAsync(String, Object, RenderingConfig, CancellationToken)
Renders a specified ZPT document file using the specified model.
Declaration
Task<Stream> RenderAsync(string filePath, object model, RenderingConfig config = null, CancellationToken token = default(CancellationToken))
Parameters
Type | Name | Description |
---|---|---|
System.String | filePath | The relative or absolute file system path of the document to render. |
System.Object | model | The model/data to be rendered by the document. |
RenderingConfig | config | An optional rendering configuration. |
System.Threading.CancellationToken | token | An optional token used to cancel/abort the operation whilst it is in-progress. |
Returns
Type | Description |
---|---|
System.Threading.Tasks.Task<System.IO.Stream> | A stream containing the rendered document. |
Remarks
The filePath
parameter should be the disk or network share path
to the source document file which is to be rendered. This may be a an absolute
path or it may be relative to the current working directory.
The model
parameter is the model which will be rendered-by/bound-to
the document template. It will be available as the pre-defined TALES variable here
during the rendering process. This model may be any arbitrary object, as appropriate to
your application/use-case.
Passing a RenderingConfig in the config
parameter is
optional. If omitted or null then Default will be used,
which is likely to be suitable for simple usages.
The cancellation token parameter token
may be used during asynchronous
operations in order to abort/cancel the operation before completion. For more information
about task cancellation see
https://docs.microsoft.com/en-us/dotnet/api/system.threading.cancellationtokensource.
The return of this method is a Task
which exposes a Stream
. That stream is
the rendered document. If you wish to copy this to a TextWriter
, for example to save
it to a file, or to write it to another output, then consider using IWritesStreamToTextWriter.