0

writing excel file value into notepad using vb.net. in my code am using oledb provider for opening the excel file.but am getting error in openning the excel file. that file named as "phone data.xlsx" . stored in my system desktop.using file upload control to get that file.

my code
-------
 Dim pathToCheck As String = filename
    If System.IO.File.Exists(pathToCheck) = "True" Then

        IO.File.Delete(filename)
    End If
    Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter("D:\modellog.txt", True, System.Text.Encoding.UTF8)

    If FileUpload2.HasFile Then
        TextBox1.Text = FileUpload2.FileName
        Dim MyConnection As System.Data.OleDb.OleDbConnection
        Dim Ds As System.Data.DataSet
        Dim MyCommand As System.Data.OleDb.OleDbDataAdapter
        Try
            MyConnection = New System.Data.OleDb.OleDbConnection(("provider=Microsoft.ACE.OLEDB.12.0; " + ("data source=" _
                                  + (TextBox1.Text + ("; " + "Extended Properties=Excel 12.0;")))))
            MyCommand = New System.Data.OleDb.OleDbDataAdapter _
                ("select * from [Sheet1$]", MyConnection)
            Ds = New System.Data.DataSet
            MyCommand.Fill(Ds)


error
-----
The Microsoft Office Access database engine cannot open or write to the file ''. It is already opened exclusively by another user, or you need permission to view and write its data.

1 Answer 1

1

Looks like a permissions issue. Have you tried copying the file somewhere else, like C:\temp? And have you tried at least temporarily granting full control to everyone on the file? If it works after that, you know it's a permissions issue and then you just have to figure out what the appropriate level of permissions is (don't want to leave it at full control for everyone).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.