From 87914ff3279526818a1b7f02ecba9fcdaf06fcc1 Mon Sep 17 00:00:00 2001 From: rlv-dan Date: Tue, 5 May 2020 18:16:38 +0200 Subject: [PATCH] Be more specific on StreamWriter and template encoding to avoid EncoderFallbackException --- Snap2HTML/frmMain_BackgroundWorker.cs | 6 ++++-- Snap2HTML/template.html | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/Snap2HTML/frmMain_BackgroundWorker.cs b/Snap2HTML/frmMain_BackgroundWorker.cs index befc9f3..5095867 100644 --- a/Snap2HTML/frmMain_BackgroundWorker.cs +++ b/Snap2HTML/frmMain_BackgroundWorker.cs @@ -53,7 +53,7 @@ namespace Snap2HTML var sbTemplate = new StringBuilder(); try { - using( System.IO.StreamReader reader = new System.IO.StreamReader( System.IO.Path.GetDirectoryName( Application.ExecutablePath ) + System.IO.Path.DirectorySeparatorChar + "template.html" ) ) + using( System.IO.StreamReader reader = new System.IO.StreamReader( System.IO.Path.GetDirectoryName( Application.ExecutablePath ) + System.IO.Path.DirectorySeparatorChar + "template.html", Encoding.UTF8 ) ) { sbTemplate.Append(reader.ReadToEnd()); } @@ -102,8 +102,10 @@ namespace Snap2HTML // Write output file try { - using( System.IO.StreamWriter writer = new System.IO.StreamWriter( settings.outputFile ) ) + using( System.IO.StreamWriter writer = new System.IO.StreamWriter( settings.outputFile, false, Encoding.UTF8 ) ) { + writer.AutoFlush = true; + var template = sbTemplate.ToString(); var startOfData = template.IndexOf( "[DIR DATA]" ); diff --git a/Snap2HTML/template.html b/Snap2HTML/template.html index a296a31..af1d911 100644 --- a/Snap2HTML/template.html +++ b/Snap2HTML/template.html @@ -1,4 +1,4 @@ - +