Saveas causing errors

Aug 3, 2011 at 3:58 PM

                if (!File.Exists(this.savePath + stripped + ".xlsx"))
                {

                    using (ExcelPackage ex = new ExcelPackage(pather))
                    {
                        FileInfo saver = new FileInfo(this.savePath.FullName + @"\New.xlsx");
                        ExcelWorksheet workSheet = ex.Workbook.Worksheets[timing];
                        workSheet.Cells["A1"].LoadFromDataTable(dt, true);
                        ex.SaveAs(saver);

                    }
                }
                else 
                {
                    
                    using (ExcelPackage ex = new ExcelPackage(existing))
                    {
                        FileInfo saver = new FileInfo(this.savePath.FullName + @"\something.xlsx");
                        ExcelWorksheet workSheet = ex.Workbook.Worksheets[timing];
                        workSheet.Cells["A1"].LoadFromDataTable(dt, true);
                        ex.SaveAs(saver);
                    }
 
                }

This is what I'm using to saveas, but I keep getting a "Error saving file C:\Documents and Settings\xxxx\Desktop\Txxxx\New.xlsx" with an invalidoperationexception error thrown. 

 

I'm sorry I'm still pretty new to this stuff so i'm sure it's a very stupid question. If you can help me I'd really appreciate it. 

 

I ran the sample code for EPP with the same "destination directory" and it worked just fine. 

Aug 4, 2011 at 5:46 PM
Edited Aug 7, 2011 at 7:12 PM

Hi I figured out this iuse, it wasn't accepting the string as a variable. 

 

However I'm having a different issue, is there something I need to do to overwrite an existing file?

 

Thanks,

Pradeep

 

[EDIT]

Hi Guys,

In the process of learning more and more about the code, I figured out what I was doing wrong. This issue has been solved. If you can delete this discussion that's great if not please ignore it.

Thanks

[Edit]