无法从磁盘读取文件

时间:2016-06-14 17:53:18

标签: vb.net excel

当我从我的vb应用程序上传excel文件时,这是第一次没问题。如果我第二次尝试这个错误:进程无法访问文件(路径),因为它被另一个进程使用。以下是我的代码:

id      key
1      method
2     algorithm

2 个答案:

答案 0 :(得分:1)

    Try
            myStream = fd.OpenFile()
            If (myStream IsNot Nothing) Then
                workbook = APP.Workbooks.Open(fd.FileName, ReadOnly:=True, Notify:=False)
                worksheet = workbook.Worksheets("sheet1")

...

    Finally
            ' Check this again, since we need to make sure we didn't throw an exception on open.
            If (myStream IsNot Nothing) Then
                myStream.Close()
            End If
            If (workbook IsNot Nothing) Then
                workbook.Close()
            End If
        End Try

答案 1 :(得分:0)

确保应用程序已关闭且没有正在运行的进程,否则它将为您提供该错误。