Error on second call to license file


#1

I have purchased Aspose.Excel and recently recieved the license file. The first time I export the data to a spreadsheet it goes fine, then the second time (during the same session) it throws the following exception below. I tried calling the .Dispose method but Aspose.Excel doesn’t have one. I also made the excel variable local to a subroutine and calling GC.Collect() and that didn’t work either.


How can I call it more than once? I can make the application variable (i.e. Aspose.Excel excel) a global variable, and only initialize it once. However, my code currentl has the Excel routines in a class that is used and disposed. The second attempt in the same session throws this error.



---------------------------

---------------------------
System.Exception: Invalid license filename or its path! at
Aspose.Excel.N1.A44() at Aspose.Excel.N1…ctor(String key, String
licenseFile) at Aspose.Excel.Excel.C26() at
Aspose.Excel.Excel…ctor(String licenseFile) at
DigitalComputations.Simware.Statistics.frmDataGrid.ExportToExcel2() in d:\dc master\simware\simware\frmdatagrid.cs:line 342
---------------------------
OK
---------------------------


#2

Hi, thanks for your consideration.

When you call save method, many data contained in the Excel object is changed to generate the result file.

To meet your need, you can try the following method:

Create a Excel object as global variable and initialize it once, when you need save it, you can try this:

//excel is global variable
Excel excel = new Excel();

//Initialize once
excel.Open(designFileName);



//Save data
//Create a local variable and copy data from global variable
Excel localExcel = new Excel();
localExcel.Copy(excel);
localExcel.Save(resultFileName, FileFormatType.Default);


#3

I think you have misunderstood me. I don’t want to be forced to use a global variable. Here is my code.

bInitExcel=true;
string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
int lastIndex = appPath.LastIndexOf("\");
appPath= appPath.Remove(lastIndex,appPath.Length - lastIndex);

string licenseFile = appPath + " \Aspose.DPExcel.lic";
excel = new Excel(licenseFile);


This is in a class called CWriteToExcel. I initialize and use the class CWriteToExcel, then dispose it and even call GC.Collect();

Then the second time my code initializes CWriteToExcel it throws the exception when it gets to excel = new Excel(licenseFile); If I close the application and restart it will work again on the first time but not on the second or subsequent.


#4


For exception,"Invalid license filename or its path! ", as I mentioned in the earlier email, it’s most probably caused by wrong license file’s PATH if you never modify the license file.

So would you use a hard code path to test this issue?

I’m very sorry it bugs you so long time but expecting your patience and understanding.



#5

Ben, as I told you in the previous email and in the previous posting, it works the first time it is called in the application. This is the sequence.

1. Appication starts
2. Application tries to write an Excel file, it works.
3. Appication tries to write an Excel file, it fails.
4. Applications ends

Your answer doesn’t make sense because it works the first time and not on subsequent attempts. The path of the license file doesn’t change during the execution.


#6

Hi,

I do the following test.

I declared a new class.

public class CWriteToExcel
{
private Excel excel;
public CWriteToExcel()
{
string appPath = System.Reflection.Assembly.GetExecutingAssembly().Location;
int lastIndex = appPath.LastIndexOf("\");
appPath= appPath.Remove(lastIndex,appPath.Length - lastIndex);

string licenseFile = appPath + " \Aspose.Excel.lic";
excel = new Excel(licenseFile);


}

public void Save()
{
excel.Save(“d:\test.xls”, FileFormatType.Default);
}


Test it in the following form button-click event.

private void button1_Click(object sender, System.EventArgs e)
{
CWriteToExcel writeExcel = new CWriteToExcel();
writeExcel.Save();
}

I clicked the button serveral times, it works fine.
So could you create a simple test case to re-create this problem and send it to me?
Sorry for this bug and thanks for your patience.