我有一个VB.Net程序,它有一些保存在文本文件中的自定义设置。现在文件保存在" settings.txt"保存在bin文件夹中。问题是这个程序被发布到我的网络,所以我的同事可以使用它,每次我推出一个新的更新,他们已保存的设置被删除;它用一个空白版本覆盖该文件。还有其他位置对我来说保存文件会更好吗?或者有没有办法(可能通过代码?)阻止我的每个同事的内容在每次发布更新时被删除?
Public Class Program
'global variables
Dim fileName As String = "settings.txt"
Private Sub Program_Load(sender As Object, e As EventArgs) Handles MyBase.Load
'code
Try
If File.Exists(fileName) = False Then
File.Create(fileName)
End If
' Open the file using a stream reader.
Using sr As New StreamReader(fileName)
Dim line As String
While (sr.EndOfStream = False)
line = sr.ReadLine()
End While
End Using
Catch ex As Exception
MsgBox(ex.ToString())
End Try
'rest of program
End Sub
End Class
答案 0 :(得分:1)
如果这是ClickOnce应用,请尝试以下操作:
Friend fileName As String = String.Empty
With My.Application.Info
fileName = IO.Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData), .CompanyName, .ProductName, .Version.ToString, "Settings.txt")
End With