2016-06-13 56 views
2

您好,大家下午好,我是在我的項目長話短說的發展我需要保存我的HTML基本頁面使用UTF8或Unicode保存vb.net HTML在UTF8或Unicode

Dim y As String 
    Dim UTF8encoding() As Byte, MyEncoder As New System.Text.UTF8Encoding(TRUE) 
    y = (html code should be here will be under) 
    Dim utf8 As New UTF8Encoding() 
    Dim utf8EmitBOM As New UTF8Encoding(True) 
    Dim code As String = y 
    Path = "C:\Users\OWNER\Desktop\invoice.html" 

    Try 
     Dim my_write As System.IO.StreamWriter 
     my_write = IO.File.CreateText(path) 
     my_write.write(utf8EmitBOM.GetPreamble()) 
     UTF8encoding = System.Text.Encoding.Convert(System.Text.Encoding.UTF8, System.Text.Encoding.Unicode, MyEncoder.GetBytes(y)) 
     my_write.WriteLine(code) 
     my_write.Close() 
    Catch ex As Exception 

    End Try 

HTML

<html> 
    <style> 
    table, th, td 
    { border: 1px solid black; } 
    </style> 
    </head> 
    <body><center><b> 
    <font size=20>Family Butcher</font></br></br></br><center><b> 
    <font size =4>164 Battersea Bridge Road London SW11 3AW</center></font><center><b> 
    <font size =4>Tel: Mob:</center></font><center><b> 
    <font size =4>VAT No: 835522334</center></br></font></br> 
    <table Border = 3 WIDTH=610 align=left></br><tr> 
    <th colspan=3 align = left>To: " & txto & " <br/> 
    <br/>Date: <br/><br/>Invoice nº <br/></th></tr> 
    <td WIDTH = 100 HEIGHT=40><center><b>Quantity </b></td> 
    <td WIDTH = 400><center><b>Description</b></td><td><center> 
    <b>Value</b> </br></p> 
    </body></html> 

我一時不知道如何保存在Unicode或UTF8的文件,然後我無法打開無符號「A」謝謝你的HTML文件的任何支持

+0

你試過File.WriteAllText? https://msdn.microsoft.com/en-us/library/ms143376(v=vs.110).aspx – Neolisk

+0

@neolist我愛你... T_T,基本上我錯過閱讀和應用文件寫所有,謝謝你好喲 –

+0

我很樂意提供幫助。請接受我的答案。 – Neolisk

回答

0

我建議你使用File.WriteAllText - this overload允許你指定的編碼,所以你可以只用一行代碼實現自己的目標,例如:

File.WriteAllText(path, code, Encoding.UTF8) 
+1

非常感謝,非常感謝您的幫助! - :d –