ArcObjects ExcelWorkspaceFactory Won't Release Excel File

المشرف العام

Administrator
طاقم الإدارة
I'm working with ArcObjects to set up a batch import from xls and csv files into a geodatabase. That part works fine, but after the import, I want to delete the file. This, however, doesn't work, because the file is still open. None of the interfaces being used descend from IDisposable or expose a Close method. I've also tried using a ComReleaser to force close all of the COM objects that I open, but that doesn't work either. The only things I've seen pertaining to closing a connection say that I need to remove all references to these types and force garbage collection, which is against standards (for good reason).

Here's the method I'm using for the excel import:

private ServiceResult InsertControlsFromXls(FileInfo xlsFile) { ServiceResult result = new ServiceResult(); using(ComReleaser comReleaser = new ComReleaser()) { //read in the spreadsheet as a workspace Type factoryType = Type.GetTypeFromProgID("esriDataSourcesOleDB.ExcelWorkspaceFactory"); IWorkspaceFactory workspaceFactory = (IWorkspaceFactory)Activator.CreateInstance(factoryType); IWorkspace workspace = workspaceFactory.OpenFromFile(xlsFile.FullName, 0); IFeatureWorkspace remoteWorkspace = (IFeatureWorkspace)OpenWorkspace(); IFeatureWorkspace featureWorkspace = (IFeatureWorkspace)workspace; IWorkspaceEdit2 session = (IWorkspaceEdit2)remoteWorkspace; IMultiuserWorkspaceEdit multiuserWorkspace = (IMultiuserWorkspaceEdit)remoteWorkspace; comReleaser.ManageLifetime(workspaceFactory); comReleaser.ManageLifetime(workspace); comReleaser.ManageLifetime(remoteWorkspace); comReleaser.ManageLifetime(featureWorkspace); comReleaser.ManageLifetime(session); comReleaser.ManageLifetime(multiuserWorkspace); try { //session.StartEditing(false); multiuserWorkspace.StartMultiuserEditing(esriMultiuserEditSessionMode.esriMESMVersioned); session.StartEditOperation(); Match tableMatch = _tableRecReg.Match(xlsFile.Name); string tableName = tableMatch.Success ? tableMatch.Groups[1].Value + "$" : "Sheet1$"; ITable table = featureWorkspace.OpenTable(tableName); result.Value = CopyAllFeatures(table, remoteWorkspace.OpenFeatureClass(AppSettings.DefaultSchema + "." + ControlMap.TableName)); session.StopEditOperation(); session.StopEditing(true); } catch { session.AbortEditOperation(); session.StopEditing(false); throw; } } return result;}I asked this question on Stack Exchange too, but no responses so far:http://stackoverflow.com/questions/30783703/arcobjects-excelworkspacefactory-wont-release-excel-file



أكثر...
 
أعلى