While copying from resources to a folder under appdata folder: i get an error, but I'm not finding any mistake in code..
Private Sub Help_Load(sender As Object, e As EventArgs) Handles MyBase.Load
File.WriteAllBytes(MainPath & "\Help.rtf", My.Resources.HelpRTF)
Dim HelpRTF = (MainPath & "\Help.rtf")
Helpbox.LoadFile(HelpRTF)
End Sub
HelpRTF
is a .rtf file, MainPath
is a directory under %appdata%
folder
Error: Value of type 'String' cannot be converted to 'Byte()'.
Error at: My.Resources.HelpRTF
答案 0 :(得分:0)
您收到该错误的原因是File.WriteAllBytes()
方法的第二个参数需要Byte()
,而不是String
。如果要将文本(String
)写入文件,可以使用File.WriteAllText()
方法。
由于RTF可以包含图像,文本等将其视为文本可能会破坏它并且不用说,可能会出现编码问题。因此,不要使用File.WriteAllText()
方法,而是将FileType
资源的HelpRTF
更改为Binary
而不是Text
,如下所示:
之后,您可以按原样使用您的代码:
Private Sub Help_Load(sender As Object, e As EventArgs) Handles MyBase.Load
File.WriteAllBytes(MainPath & "\Help.rtf", My.Resources.HelpRTF)
Dim HelpRTF = (SWinPath & "\Help.rtf")
Helpbox.LoadFile(HelpRTF)
End Sub
参考文献: