Private Sub Button7_Click(sender As Object,e As EventArgs)处理Button7.Click
Dim Newline As String Newline = System.Environment.NewLine System.IO.File.WriteAllLines("C:\Users\Sang\Desktop\filename.txt", Result1.Lines) System.IO.File.AppendAllLines("C:\Users\Sang\Desktop\filename.txt", Result2.Lines) System.IO.File.AppendAllLines("C:\Users\Sang\Desktop\filename.txt", values.Lines) End Sub这是我在桌面上制作文本文件的编码。 但是,我的朋友无法运行此代码,因为此代码仅供我自己使用,如上所示。 我想使用folderbroswerdialog来为每个人推广这个编码。 具体来说,如果用户在表单上按下此按钮,文件夹浏览器应该询问他要保存此文本文件的位置,文本文件应保存在定向文件夹或桌面中。 我试着通过查看许多YouTube视频和资源来自己做,但我失败了。 我该怎么办呢?
Private Sub Button7_Click(sender As Object, e As EventArgs) Handles Button7.Click
Dim Newline As String Newline = System.Environment.NewLine System.IO.File.WriteAllLines("C:\Users\Sang\Desktop\filename.txt", Result1.Lines) System.IO.File.AppendAllLines("C:\Users\Sang\Desktop\filename.txt", Result2.Lines) System.IO.File.AppendAllLines("C:\Users\Sang\Desktop\filename.txt", values.Lines) End SubThis is my coding for making a text file on my desktop. However, my friend can not run this code because this code is only for myself as you can see above. I would like to use a folderbroswerdialog to generalize this coding for everyone. To be specific, if a user pressed this button on the form, folder browser should ask him where he wants to save this text file and text file should be saved in the directed folder or desktop. I tried to do it on my own by looking at many youtube videos and resources but I failed. How should I proceed this?
最满意答案
您可以使用Environment.SpecialFolder枚举,其中包含可以使用Environment.GetFolderPath方法检索的系统目录的大小:
Dim DesktopDir As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)然后,您可以使用Path.Combine方法正确组合目录/文件路径:
Dim OutputFile As String = IO.Path.Combine(DesktopDir, "filename.txt")然后:
IO.File.WriteAllLines(OutputFile, "Text Here")You can use the Environment.SpecialFolder Enumeration which contains the ubications of the system's directories that you can retrieve using Environment.GetFolderPath method :
Dim DesktopDir As String = Environment.GetFolderPath(Environment.SpecialFolder.Desktop)Then you can use the Path.Combine method to properlly combine a directory/file path:
Dim OutputFile As String = IO.Path.Combine(DesktopDir, "filename.txt")Then:
IO.File.WriteAllLines(OutputFile, "Text Here")更多推荐
发布评论