user2824519
user2824519

Reputation: 43

Open file in share mode using excellibrary

I am using excellibrary to process excel files. Right now to open the file I am using

ef = Workbook.Load(file)

But if that file is opened somwhere else in another application when I try to access it I get the message:

The process cannot access the file '\OFFICE\MyDocumentsWD\VB2010\Projects\Excel File Checker\Excel File Checker\Test1.xls' because it is being used by another process.

I know that when using streamreader you can use fileshare option and I wonder if there is similar option when working with excellibrary? Or is there workaround to accomplish the same?

Upvotes: 0

Views: 1029

Answers (1)

Graymatter
Graymatter

Reputation: 6587

Workbook does support streams so you have a couple of options.

I think you should open the file into a memory stream and then load from that memory stream with something like this:

MemoryStream memory = new MemoryStream(file);
ef = Workbook.Load(memory);

Alternatively you should be able to load the file using a filestream like this:

FileStream fileStream = new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.Read);
ef = Workbook.Load(fileStream);

Upvotes: 1

Related Questions