使用资源 visual basic 中的文本写入文件

Write File with text from resources visual basic

我正在 VB 中编写一些程序,我想用资源文件中的文本创建 txt 文件。你没有听懂,是吗?所以,它是这样的。

 Dim path As String = "c:\temp\MyTest.txt" 

    ' Create or overwrite the file. 
    Dim fs As FileStream = File.Create(path)

    ' Add text to the file. 
    Dim info As Byte() = New UTF8Encoding(True).GetBytes("This is some text in the file.")
    fs.Write(info, 0, info.Length)
    fs.Close()

是创建带有特定文本的txt文件的代码。但是,我需要以下内容。

 Dim fd As New FolderBrowserDialog
    fd.ShowDialog()

is the only function that I have in program, and, when folder is selected, I need to create file in that folder, file's name should be config.cfg, but, text in file which is going to在所选文件夹中创建的应该是资源中我的 txt 文件中的文本。

我试过了

 Dim path As String = fd.SelectedPath 
    Dim fs As FileStream = File.Create(path)

    ' upisuje tekst u fajl 
    Dim info As Byte() = New UTF8Encoding(True).GetBytes(application.startuppath &  "\..\..\Resources\config.cfg")
    fs.Write(info, 0, info.Length)
    fs.Close()

但是我在文件中得到的文本是我的程序调试所在的目录。 有什么想法可以做到这一点吗? :)

如果您向资源中添加了文本文件,那么您可以尝试这样的操作:

Using fbd As New FolderBrowserDialog
  If fbd.ShowDialog(Me) = DialogResult.OK Then
    File.WriteAllText(Path.Combine(fbd.SelectedPath, "config.cfg"), My.Resources.config)
  End If
End Using

我添加的文件叫config,它在我的资源库里做了一个config.txt文件。