Word Reports
DocumentFactory(Stream) Method
Example 



KellermanSoftware.WordReports Namespace > WordReportsGenerator Class > DocumentFactory Method : DocumentFactory(Stream) Method
Creates a new Document In Memory
Syntax
Public Overloads Function DocumentFactory( _
   ByVal sourceDocumentStream As Stream _
) As Document
Dim instance As WordReportsGenerator
Dim sourceDocumentStream As Stream
Dim value As Document
 
value = instance.DocumentFactory(sourceDocumentStream)
public Document DocumentFactory( 
   Stream sourceDocumentStream
)
public:
Document^ DocumentFactory( 
   Stream^ sourceDocumentStream
) 

Parameters

sourceDocumentStream

Return Value

Instantiated Document
Example
//To run this example code, create a word document called ExampleTemplate.docx with the text [ReplaceMe] in the document
 
WordReportsGenerator generator = new WordReportsGenerator(); //Trial Mode
//WordReportsGenerator generator = new WordReportsGenerator("place user name here", "place license key here"); //License Mode
 
const string sourceDocumentPath = @"Test Documents\ExampleTemplate.docx";
const string outputDocumentPath = "ExampleOutput.docx";
 
using (FileStream inputStream = new FileStream(sourceDocumentPath, FileMode.Open, FileAccess.Read))
{
    using (Document document = generator.DocumentFactory(inputStream))
    {
 
        Dictionary<string, ReplacementItem> replacement =
            new Dictionary<string, ReplacementItem>
                {
                    {
                        "[ReplaceMe]",
                        new ReplacementItem {Value = "This is a test"}
                    }
                };
 
        generator.Replace(document, replacement);
 
        using (FileStream outputStream = new FileStream(outputDocumentPath, FileMode.Create, FileAccess.Write))
        {
            generator.SaveDocument(document, outputStream);
        }
    }
}
'To run this example code, create a word document called ExampleTemplate.docx with the text [ReplaceMe] in the document
 
Dim generator As New WordReportsGenerator() 'Trial Mode
'WordReportsGenerator generator = new WordReportsGenerator("place user name here", "place license key here"); //License Mode
 
Const sourceDocumentPath As String = "Test Documents\ExampleTemplate.docx"
Const outputDocumentPath As String = "ExampleOutput.docx"
 
Using inputStream As New FileStream(sourceDocumentPath, FileMode.Open, FileAccess.Read)
    Using document As Document = generator.DocumentFactory(inputStream)
 
        Dim replacement As New Dictionary(Of String, ReplacementItem)() From {{ "[ReplaceMe]", New ReplacementItem With {.Value = "This is a test"} }}
 
        generator.Replace(document, replacement)
 
        Using outputStream As New FileStream(outputDocumentPath, FileMode.Create, FileAccess.Write)
            generator.SaveDocument(document, outputStream)
        End Using
    End Using
End Using
Requirements

Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also

Reference

WordReportsGenerator Class
WordReportsGenerator Members
Overload List