Home

Close Excel File After execution

I am reading some data from an excel sheet, processing it, and saving it to another Excel file. I am using LinqToExcelModern

I would like to move the file from the 'To Do' directory to a 'Done' directory, but I can't figure out how to close/dispose of the file. The file seems to remain in use by my linqpad query until i take some action (like saving the query, or starting and stopping it)

My code is as follows:


void Main()
{
IQueryable importItems;
string fileName;

using (ExcelQueryFactory excel = new ExcelQueryFactory(fullPath))
{
    excel.UsePersistentConnection = false;
    excel.ReadOnly = true;

    importItems = excel.Worksheet<importtemplate>("sheet1");
    excel.Dispose();//i tried this, doesn't seem to do anything
};

//do some processing

   //save  (this works fine)    
Util.ToSpreadsheet(processedItems, "Sheet1", true).Save(completePath);

   //move file
   File.Move(fullPath, dest);       //file is still in use at this point, so i get an error

//it is also in use if i try to move it manually in windows. Tell mes file is open in LinqPad, even after execution has stopped 

}

Comments

Sign In or Register to comment.