0

I have an excel file which is already open by another user. Please help me out how to read it. I have tried by using following code with READONLY=TRUE in C#, but yet it dint solve my issue.

string stringConExcelMat = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\\PER_Sample\\Input\\6787GHHDSGioSack_v02.xls;Extended Properties=""Excel 8.0;HDR=NO;IMEX=1;READONLY=TRUE""";


DataTable TTable = new DataTable("TABLEMAT");
using (OleDbConnection conn = new OleDbConnection(stringConExcelMat))
{
     conn.Open();
     using (OleDbDataAdapter da = new OleDbDataAdapter("SELECT * FROM [Raw_Data$A:T]", conn))
     {
         da.Fill(TTable);
     }
}
DataRow RowValues = TTable.Rows[1];
Soner Gönül
  • 97,193
  • 102
  • 206
  • 364
user3789961
  • 135
  • 3
  • 12
  • 1
    Well, I don't know what you're doing, but if you have a need for many users to use one data source, then I suggest Excel is not the way to go. Use a database instead (e.g. Access, SQL Server, Mysql, Postgresql...). – mlinth Nov 04 '14 at 08:44
  • 1
    Well, I think you won't be able to solve, since Excel requires a lock on the file. Have you tried first to copy the file and read the copied file? You can also try to use [FileStream and FileShare enum](http://stackoverflow.com/a/898017/702048) (that it should be the best solution). – Alberto Solano Nov 04 '14 at 08:50
  • I have tried using SQL Server too. it is not possible in SQL. – user3789961 Nov 04 '14 at 09:02
  • You better use FileStream for readonly. check this url: http://www.codeproject.com/Articles/16210/Excel-Reader – Paresh J Nov 04 '14 at 11:30

0 Answers0