我的代码我使用streamwriter打开/创建一个文件并写入它。这在调试模式下工作正常,但在运行可执行文件时出现“权限被拒绝”错误。这是下面有问题的代码。
Left out part of the code in first post, here's the correct snippet:
Dim DateOfTest As Date
Dim TesterName As String
Dim SerialNumber As String
TesterName = TextBoxTester.Text
DateOfTest = Now
SerialNumber = TextBoxBoardSN.Text
'File writing for test info
Dim path As String = "C:\" & SerialNumber & ".txt"
If File.Exists(path) Then
File.Delete(path)
End If
' Create the file.
Dim writer As StreamWriter = New StreamWriter(path)
writer.WriteLine("CPX Loopback Test " & vbCrLf)
writer.WriteLine("Serial Number " & vbTab & "Tester Name" & vbTab & "Date")
writer.WriteLine(SerialNumber & vbTab & vbTab & TesterName & vbTab & vbTab & DateOfTest & vbCrLf)