When exporting data from a XamDataGrid I get a error when opening the file in Excel that says the file is locked by another application. The filename is new each time I export and is based on the current time as shown below.
string filename = "MyGrid" + DateTime.Now.ToString("MMM-dd-yyyy hh-mm-ss") + ".xlsx"; DataPresenterExcelExporter exporter = new DataPresenterExcelExporter(); exporter.Export(grid, filename, WorkbookFormat.Excel2007); Process p = new Process(); p.StartInfo.FileName = filename; p.Start();
If I call Thread.Sleep(1000) right after the .Export call, everything works fine but I'd like to find a better solution than that. And just to be clear, I'm very confident there are no other threads or applications that are locking the file, I believe it's the DataPresentExcelExporter that hasn't let go of the file yet.
There's some more odd behavior...
- This only happens the FIRST time I export from a grid. Every time after that for the same grid works. However, if I export data from a different grid, I get the read-only thing the first time.
- This read-only issue only happens if I already have Excel running before I export.
Is there are better way to implement the opening of the file or any ideas on how I could prevent the read-only lock?
Hello WpfDeveloper,
Just checking in as it has been a couple of weeks since I have last heard from you. Did you still require assistance on this matter?
Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support
Thank you for your response.
I will await your next update on this matter. Please let me know if you have any other questions or concerns on this matter.
This problem exists for me when I run the sample solution you sent. However I am running version 14.1.20141.2108 and have not had an opportunity to update Infragistics yet. I'll will install the latest version as soon as I can and report back the results.
Just checking in, did you have any other questions or concerns on this matter?
Hello WpfDeveloper,I followed the steps you suggested and was unable to reproduce the behavior you're describing. Using a XamDataGrid with 4 columns and 2500 records, I exported to the grid using the code you provided with and without Excel open. I did not see this read-only behavior you are describing.I have attached the sample project I used to test this. Please test this project on your PC; whether or not it works correctly may help indicate the nature of this problem.If the project does not work correctly, this indicates either a problem possibly specific to your environment, or a difference in the DLL versions we are using. My test was performed using version 14.2.20142.2081 in Infragistics for WPF 2014 Volume 2. Is this the version you are using as well?If the project does show the product feature working correctly, this indicates a possible problem in the code of your application. It will help if you can provide a small, isolated sample application that demonstrates the behavior you are seeing.Or, if this sample project is not an accurate demonstration of what you're trying to do, please feel free to modify it and send it back, or send a small sample project of your own if you have one.Please let me know if I can provide any further assistance.Sincerely,AndrewAssociate DeveloperInfragistics Inc.www.infragistics.com/support