Read protect excel using aspnet

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.
 
S

sweetpotatop

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.
 
S

sweetpotatop



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.
 
M

Mark Rae

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...?
 
S

sweetpotatop

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.
 
M

Mark Rae

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...
 
S

sweetpotatop

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
 
M

Mark Rae

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...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top