Read protect excel using aspnet

  • Thread starter Thread starter sweetpotatop
  • Start date Start date
S

sweetpotatop

Hi,

I wonder if it is possible to read the content of an excel spreadsheet
through aspnet. The spreadsheet (workbook) is protected and it resides
in a network drive.

Please provide sample code if possible. Thanks in advance. Your help
is greatly appreciated.
 
What if it is not password protected, is it possible to read the
sheets (more than 1) in the workbook and how can this be done?

Thanks.
 


Thanks for your advice, but I am getting the following error once
objConn.Open is executed

System.Data.OleDb.OleDbException: Unspecified error

Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
_
& "Data Source=C:\test.xls" _
& ";" & "Extended Properties=Excel 11.0;"

' Create the connection object by using the preceding
connection string.
Dim objConn As New OleDbConnection(sConnectionString)

' Open connection with the database.
objConn.Open()

Is it something to do with the Extended Properties? I have been trying
8.0 to 11.0, but none of them work. The file is created through MS
Excel 2003. Or something is missing on the machine?

Please help. Your help is greatly appreciated.
 
Thanks for your advice, but I am getting the following error once
objConn.Open is executed

System.Data.OleDb.OleDbException: Unspecified error

Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;"
_
& "Data Source=C:\test.xls" _
& ";" & "Extended Properties=Excel 11.0;"

' Create the connection object by using the preceding
connection string.
Dim objConn As New OleDbConnection(sConnectionString)

' Open connection with the database.
objConn.Open()

Is it something to do with the Extended Properties?

You need to catch the exception and then inspect the inner exception to find
out what precisely is going wrong...

Also, is text.xls actually present in the root directory of your
webserver...?
 
You need to catch the exception and then inspect the inner exception to find
out what precisely is going wrong...

Also, is text.xls actually present in the root directory of your
webserver...?- Hide quoted text -

- Show quoted text -


No luck, unfortunately, I have moved the test.xls to the root
directory of the web application (see below)

Dim sConnectionString As String =
"Provider=Microsoft.Jet.OLEDB.4.0;" _
& "Data Source=" &
Server.MapPath("./test.xls") _
& ";" & "Extended Properties=Excel
11.0;"

And I try to catch the exception but I am still getting "Unspecified
error "
Try
objConn.Open()
Catch ex As Exception
Page.RegisterStartupScript("Cannot Open",
"<script>window.alert('" & (ex.Message.ToString) & "' );</script>")
Exit Sub
End Try

Please help. I really need to get this resolved. Many thanks.
 
And I try to catch the exception but I am still getting "Unspecified
error "
Try
objConn.Open()
Catch ex As Exception
Page.RegisterStartupScript("Cannot Open",
"<script>window.alert('" & (ex.Message.ToString) & "' );</script>")
Exit Sub
End Try

Please help. I really need to get this resolved. Many thanks.

Like I said, you need to interrogate the InnerException property of the
Exception object, not the Message property...
 
Like I said, you need to interrogate the InnerException property of the
Exception object, not the Message property...


I have something like this, but "InnerException Is Nothing", so I
can't any message at all. Please help!!!

Try
objConn.Open()
Catch ex As Exception
'lblError.Text = ex.Message.ToString

If Not (ex.InnerException Is Nothing) Then
Page.RegisterStartupScript("Cannot Open",
"<script>window.alert('" & (ex.InnerException.ToString) & "' );</
script>")
End If
Exit Sub
End Try
 
Perfect! It is working now -- the permission to the
C:\Documents and Settings\MachineName\ASPNET\Local Settings\Temp
folder

Thanks a trillion.

I think, in the end, all I did was tell you to do a Google search... :-)

For virtually every problem, that's the place to start...
 
Back
Top