internal static byte[] OpenInclude(GetIncludeEventArgs ea, ExcelFile Workbook) { string iPath = Workbook.ActiveFileName; try { if (iPath.Length > 0) { iPath = Path.GetDirectoryName(iPath) + Path.DirectorySeparatorChar; } } catch (ArgumentException) { iPath = String.Empty; } if (Path.IsPathRooted(ea.FileName)) { iPath = String.Empty; } ea.FileName = iPath + ea.FileName; using (FileStream f = new FileStream(ea.FileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) //FileShare.ReadWrite is the way we have to open a file even if it is being used by excel. { byte[] Result = new byte[f.Length]; Sh.Read(f, Result, 0, Result.Length); return(Result); } }
private void ordersReport_GetInclude(object sender, FlexCel.Report.GetIncludeEventArgs e) { Assembly a = Assembly.GetExecutingAssembly(); using (Stream InStream = a.GetManifestResourceStream("TemplatesOnTheExe.Templates." + e.FileName)) { byte[] data = new byte[InStream.Length]; InStream.Position = 0; InStream.Read(data, 0, data.Length); e.IncludeData = data; } }