WriteFiles Class


Writes the content of each input document to the file system.
Base Types
  • Object
Derived Types
graph TD Base0["Object"]-->Type Interface0["IModule"]-.->Type click Interface0 "/api/Wyam.Common.Modules/IModule" Type["WriteFiles"] class Type type-node Type-->Derived0["UnwrittenFiles"] click Derived0 "/api/Wyam.Core.Modules.IO/UnwrittenFiles"


public class WriteFiles : IModule


If the metadata keys WriteFileName (which requires RelativeFileDir to be set, usually by the ReadFiles module), WriteExtension (which requires RelativeFilePath to be set, usually by the Wyam.Core.Modules.IO.ReadFiles module) or WritePath are set on an input document, that value will be used instead of what's specified in the module. For example, if you have a bunch of Razor .cshtml files that need to be rendered to .html files but one of them should be output as a .xml file instead, define the WriteExtension metadata value in the front matter of the page.


Name Summary
WriteFiles() Writes the document content to disk with the same file name and relative path as the input file. This requires metadata for RelativeFilePath to be set, which is done by the Wyam.Core.Modules.IO.ReadFiles module or can be set manually.
WriteFiles(DocumentConfig) Uses a delegate to describe where to write the content of each document. The output of the function should be either a full path to the disk location (including file name) or a path relative to the output folder.
WriteFiles(string) Writes the document content to disk with the specified extension with the same base file name and relative path as the input file. This requires metadata for RelativeFilePath to be set (which is done by default by the Wyam.Core.Modules.IO.ReadFiles module).


Name Value Summary
Append(bool) WriteFiles
Appends content to each file instead of overwriting them.
Execute(IReadOnlyList<IDocument>, IExecutionContext) IEnumerable<IDocument>
This should not be called directly, instead call IExecutionContext.Execute() if you need to execute a module from within another module.
GetOutputPath(IDocument, IExecutionContext) FilePath
Gets the output path of the input document.
IgnoreEmptyContent(bool) WriteFiles
Ignores documents with empty content, which is the default behavior.
OnlyMetadata(bool) WriteFiles
Indicates that only metadata should be added to the document and a file should not actually be written to the file system. This is useful for preprocessing documents so they appear in a pipeline with the correct write metadata, while actually writing them later with a second Wyam.Core.Modules.IO.WriteFiles module invocation. Only the following metadata values are written when this flag is turned on: WritePath, RelativeFilePath, RelativeFilePathBase, and RelativeFileDir. The Destination... metadata values are not added to the document when only setting metadata..
ShouldProcess(IDocument, IExecutionContext) bool
Checks whether the input document should be processed.
UseWriteMetadata(bool) WriteFiles
By default the metadata values for WritePath, WriteFileName, and WriteExtension are checked and used first, even if a delegate is specified in the constructor. This method can be used to turn off the default behavior and always rely on the delegate for obtaining the write location.
Where(DocumentConfig) WriteFiles
Specifies a predicate that must be satisfied for the file to be written.