2012-09-16 104 views
0

我想用VB.NET打開一個隨機訪問文件當我試圖訪問文件Error 75 (Access to the path ....is denied)時遇到以下錯誤消息。有什麼我必須改變來解決這個問題嗎?如何訪問VB.NET中的隨機訪問文件

Structure StdSections 
    'UPGRADE_WARNING: Fixed-length string size must fit in the buffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="3C1E4426-0B80-443E-B943-0627CD55D48B"' 
    <VBFixedString(15), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=15)> Public A() As Char 'BEAM --- complete beam designation   15 
    'UPGRADE_WARNING: Fixed-length string size must fit in the buffer. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="3C1E4426-0B80-443E-B943-0627CD55D48B"' 
    <VBFixedString(2), System.Runtime.InteropServices.MarshalAs(System.Runtime.InteropServices.UnmanagedType.ByValArray, SizeConst:=2)> Public B() As Char 'DSG --- shape ie "W" or "C"    2 
    Dim C As Single 'DN --- nominal depth of section   4 
    Dim d As Single 'WGT --- weight        4 
    . 
    . 
    . 
End structure 
''Note 'File1' holds complete path! 
     Public std As StdSections 
     Dim i,ffr,fLength,lastmembNo as integer 
     sectionFound = False 

     fLength = Len(std) 
     If fLength = 0 Then fLength = 168 ' 177 
     ffr = FreeFile() 
     'FileOpen(ffr, File1, OpenMode.Random, , , fLength) 
     FileOpen(ffr, File1, OpenMode.Random, OpenAccess.ReadWrite, OpenShare.LockRead, fLength) 
     >>Error 75 (Access to the path ....is denied) << path is perfectly good!!! 
     lastmembNo = CInt(LOF(ffr)) \ fLength 
     'ReDim std(lastmembNo) 
     For i = 1 To lastmembNo 
      FileGet(ffr, std, i) 
       If Trim(memberID) = Trim(std.A) Then 
        sectionFound = True 
       end if 
     next i 
+0

微軟在嘗試使VB6像.NET代碼一樣工作時並沒有爲我們提供幫助。重寫你的文件訪問喲使用適當的.NET工具 - 文件流 - 並從字節緩衝區手動解析字段。 –

+0

我改變了我的實現,但現在讀取隨機訪問文件時出現另一個錯誤。我發佈了一個新線程,如果你可能知道發生了什麼? http://stackoverflow.com/questions/12452991/how-to-correctly-read-a-random-access-file-in-vb-net – Matthew

回答

0

要檢查的第一件事是對有問題的文件的權限。 「訪問路徑被拒絕」並不表示路徑是壞的或無效的,但是您沒有權限,或者文件被另一個進程鎖定。另一種可能性是路徑變量中的錯字(示例中的File1)

+0

我改變了我的實現,但我現在閱讀隨機訪問時出現另一個錯誤文件。我發佈了一個新線程,如果你可能知道發生了什麼? http://stackoverflow.com/questions/12452991/how-to-correctly-read-a-random-access-file-in-vb-net – Matthew