0

I just came up with this issue, we have a library that uses Reflection to manipulate Excel files. When a user is trying to save a file that has a . in the file name (eg: 01.02.xls) it won't include .xls in the saved file (result: 01.02).

workbook.GetType().InvokeMember("SaveAs", BindingFlags.InvokeMethod, null, workbook, new Object[] { filepath.Remove(filepath.LastIndexOf(".")), 56 });

Is there an option that allows . inside the file name?

pnuts
  • 58,317
  • 11
  • 87
  • 139
user3223834
  • 59
  • 1
  • 1
  • 9

1 Answers1

0

Why do you remove .xls from your filepath with

filepath.Remove(filepath.LastIndexOf("."))

I just tested this myself, if I use just filepath as in

workbook.GetType().InvokeMember("SaveAs", BindingFlags.InvokeMethod, 
null, workbook, new Object[] { filepath, 56 });

it works for me

Rainer Schaack
  • 1,558
  • 13
  • 16
  • Thanks @ReinerSchaack I thought the same at some point but I believe there is reason for that (may be not a good one), there are so many apps that use this library that I'll need to try to test on all of them first. – user3223834 Feb 12 '15 at 13:50
  • Ok, I believe is because if someone write the file name with an extension different than .xls (such as .xslx) it will have a compatibility issue. But that can be handled, so I'll do as you suggested. Thank you @Rainer – user3223834 Feb 12 '15 at 14:28