1 private void Compact() 2 { 3 IWorkspaceName pWSName = new WorkspaceNameClass(); 4 pWSName.WorkspaceFactoryProgID = "esriDataSourcesGDB.AccessWorkspaceFactory"; 5 pWSName.PathName = "c:/Users/Administrator/Desktop/TEST.mdb"; 6 MessageBox.Show(pWSName.Type.ToString()); 7 ILocalDatabaseCompact pLDCom = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactoryClass(); 8 pLDCom.Compact(pWSName); 9 }
public void Compact_1() { IWorkspaceFactory pWSFactory = new ESRI.ArcGIS.DataSourcesGDB.AccessWorkspaceFactoryClass(); IWorkspace pWSpace = pWSFactory.OpenFromFile(string.Format("e:/2/{0}{1}", j, ".mdb"), 0); IDatabaseCompact pDBCompact = pWSpace as IDatabaseCompact; if (pDBCompact.CanCompact()) { pDBCompact.Compact(); } }
若需要压缩其他类型,更改pWSName的WorkspaceFactoryProgID属性即可,
手动着重号:只是提供这个方法,具体应用慎重,先备份数据!!!,亲测:压缩率可达到0.61%!!
修改日期:20181105,
修改内容:新加方法,相比第一种方法速度更高,耗时约为第一种方法的一半。