Windows Form: xlWorkBook.SaveAs

0

I am starting in the world of programming, and I have made a simple application, which is composed of a combobox (called cmbItemsEquipos), and when using the reference in excel to save the XLS file, I throw error.

String NameFile = String.Format("ClientesNoagregadosClaimPos{0}.xls", DateTime.Now.ToString("yyyymmddhhh"));

xlWorkBook.SaveAs(string.Format("C:\{0}-{1}", cmbItemsEquipos.SelectedText, NameFile), Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, misValue, misValue, misValue, misValue, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, misValue, misValue, misValue, misValue, misValue);

and the following error is thrown at me:

  

Unhandled exception of type 'System.Runtime.InteropServices.COMException' in ClaimPosCurrier.exe   Additional information: Microsoft Excel can not access the file 'C: \'.

There may be several reasons:

• File name or path does not exist.
• Another program is using the file.
• The book you are trying to save has the same name as another book that is currently open.

Why is it? My purpose is to save the XLS file based on the item selected from the cmbItemsEquipment ... **

Greetings.

    
asked by Brahyan Medina 07.03.2017 в 15:26
source

1 answer

0

You are having problems with a permissions issue, it is not valid to save a file in the root C:, for that you should try running the application as administrator. And as a tip in the save put a try catch, since you are taking the name of the file from a ComboBox and it is possible that you may end up having an invalid character for file name like a: o / and have an error in the application

    
answered by 09.03.2017 / 15:40
source