c# - Can Workbooks.Open() method detect whether file is already open? -


there lot of similar questions not looking for.

i using excel interop in c# working excel files. want know whether excel interop's workbooks.open() method can detect if file open. there parameters can set workbooks.open() method raises exception if file open other user. currently, doesn't seem raise exception if file in use other user.

please scope answers whether possible using workbooks.open(). there answers on stackoverflow related using system.io.file purpose.

if workbook open same excel process:

you can iterate through workbooks collection , check if file present in collection. should indicate file open.

bool isopened = workbooks.firstordefault(p=>p.fullname == filename);  if (!isopened){   workbooks.open(filename); } 

if workbook open other process:

workbooks.open supports following parameters

string filename  object updatelinks, object readonly, object format, object password, object writerespassword, object ignorereadonlyrecommended, object origin, object delimiter, object editable, object notify, object converter, object addtomru, object local, object corruptload 

the open method not provide parameter behavior. alternatively open file in editable mode , check property readonly of workbook see if file in use process.

var workbook = workbooks.open(filename,                 type.missing, false, type.missing, type.missing, type.missing, type.missing, type.missing, type.missing,                 type.missing, type.missing, type.missing, type.missing, type.missing, type.missing);  if (workbook.readonly){   // opened process; }