2013-08-16 43 views
0

我的代碼我使用Streamwriter打開/創建一個文件並寫入它。這在調試模式下工作正常,但運行可執行文件時出現「權限被拒絕」錯誤。以下是以下代碼。文件訪問可以在調試但在VB.net中不可執行

 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) 
+0

更大的視覺工作室的特權有你解決吧? –

回答

3

嘗試:右鍵點擊=>以管理員身份運行

如果解決了這個問題,這是由於比那些中的.exe

相關問題