Friday, June 19, 2015

Fix MHT if missing two "-" at the end of file

Below seemed to work for me.

  Sub Main()
        Dim inputfile As String = "c:\6.mht"
        FixMht(inputfile)

    End Sub
    Private Sub FixMht(ByVal tempFileName As String)
        Dim all As String = File.ReadAllText(tempFileName)
        Dim last As Integer = all.LastIndexOf("------=_NextPart_000_00")
        Dim newall As String = all.Remove(last)
        Dim builder As New StringBuilder
        builder.Append(newall)
        builder.Append("------=_NextPart_000_00--")
        File.WriteAllText(tempFileName, builder.ToString, Encoding.UTF8)

    End Sub

No comments:

Post a Comment