Open a shared excel file that's in use

Nov 30, 2016 at 7:55 AM
Hi,

I'd like to know if it's possible to open an excel file thats constantly in use?

I just need to read some data from it.
If you open it in excel, you get a prompt to just open the file in read only mode. Can I do something similar in code?

This:

using (ExcelPackage xlPackage = new ExcelPackage(existingFile))

generates a 'file in use' error.

Thanks!
Kenneth
Nov 30, 2016 at 8:23 AM
Just solved my own question :)

If anyone is interested :

Read the file in a filestream where you set the right attributes on the stream.
Then read the stream with excelpackage instead of the file :
        using (Stream st = new FileStream(fileLocation,
                             FileMode.Open,
                             FileAccess.Read,
                             FileShare.ReadWrite))
        {
            using (ExcelPackage xlPackage = new ExcelPackage(st))
            {
              //code
            }
         }

Greets,
Kenneth