Free Support Forum -

ThreadSave or not ? multiple openings of same file but saving with unique names


with I want to export data to excel. I have a excel-template and I want to use it like the code shown below.

Is the code thread-save when multiple threads (session users) open the same file but save under different names ?

string uniqueFileName= ...;
Workbook workbook = new Workbook();
FileStream fstream = new FileStream("template.xls", FileMode.Open);
// do some writings in the workbook
// like workbook.Worksheets[0].Cells["A1"].PutValue("blah");
workbook.Save(uniqueFileName, FileFormatType.Default);
... then stream File uniqueFileName to Asp.Net output stream

Thanks, Markus Loibl

If you change your code to the following then everything should be fine.

FileStream fstream = new FileStream("template.xls", FileMode.Open, FileAccess.Read);