A.G.
A.G.

Reputation: 2149

OLEDBConnection to Excel does not like network share path

I need to connect to an excel file on a network share o read the workbook. If the file is local, then it works but when the file is on a network share and I use this as my datasoure:

"\\Server\\MyShare\\Testing\\InputFiles\\Test_ReportInput.xlsx"

it throws this error:

'C:\Server\MyShare\Testing\InputFiles\Test_ReportInput.xlsx' is not a valid path. Make sure that the path name is spelled correctly and that you are connected to the server on which the file resides.

It pre-pended C:\ on the original path. Obviously the path nor file exist when C:\ is added.

Does this not work with network shares? Or do I need to tell it somehow not to use C:\?

Upvotes: 0

Views: 1036

Answers (2)

carloandaya
carloandaya

Reputation: 306

Can you map your network share so that it has a drive letter and use that?

In Windows Explorer, right-click on the shared folder and select "Map Network Drive...".

*Just saw your 4 slashes solution and that looks better. Thanks.

Upvotes: 0

A.G.
A.G.

Reputation: 2149

Oh, just had to do this:

"\\\\Server\\MyShare\\Testing\\InputFiles\\Test_ReportInput.xlsx"

4 \ at start.

Upvotes: 1

Related Questions