Getting error while creating new sheet from existing sheet

May 21, 2014 at 9:36 AM
I am trying to create a excel sheet from existing one, but getting error
    public string RunSample22(DirectoryInfo outputDir)
    {
        FileInfo tempFile = new FileInfo(@"F:\bin\Debug\ReportTemplateFile.xlsx");

        // Making a new file 'Sample2.xlsx'
        FileInfo newFile = new FileInfo(@"E:\Test" + @"\Sample22.xlsx");

        if (newFile.Exists)
        {
            newFile.Delete();
            newFile = new FileInfo(outputDir.FullName + @"\Sample22.xls");
        }

        using (ExcelPackage package = new ExcelPackage(newFile, tempFile ))   // getting error in this line
        {
            // Openning first Worksheet of the template file i.e. 'Sample1.xlsx'
            ExcelWorksheet worksheet = package.Workbook.Worksheets[1];

            worksheet.Cells[1, 1].Value = "Test";

            // Save our new workbook
            package.Save();
        }
        return newFile.FullName;
    }

Error - File contains corrupted data.

could anyone help me?