替换mxd的shp图层的数据源后保存时,报错{System.Runtime.InteropServices.COMException (0x80030021): 未找到数据库,请问这是什么原因?
arcengine10.2进行add-in开发,错误信息:{System.Runtime.InteropServices.COMException (0x80030021): 未找到数据库。
在 ESRI.ArcGIS.Carto.MapDocumentClass.Save(Boolean bUseRelativePaths, Boolean bCreateThumnbail)
代码:
IMapDocument mapDoc = new MapDocumentClass();
mapDoc.Open(mxdPath);
IDataSourceHelperMapDocument repairment = new DataSourceHelperClass();
IWorkspaceName oldWorkspaceName = new WorkspaceNameClass();
oldWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
oldWorkspaceName.PathName = oldPath;
IWorkspaceName newWorkspaceName = new WorkspaceNameClass();
newWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
newWorkspaceName.PathName = System.IO.Path.Combine(newPath, fileName);
repairment.ReplaceWorkspaceName(mapDoc, oldWorkspaceName, newWorkspaceName, true);
mapDoc.Save(true, true);
第二种方法:
IMapDocument mapDoc = new MapDocumentClass();
mapDoc.Open(mxdPath);
IMap pMap = mapDoc.get_Map(0);
ILayer pLayer = GetLayerByName(layerName, pMap);
IDataLayer dataLayer = (IDataLayer)pLayer;
IDatasetName pDsName = (IDatasetName)(dataLayer.DataSourceName);
IWorkspaceName ws = pDsName.WorkspaceName;
string path = "test2";
string newPath = System.IO.Path.Combine(folderPath, path);
ws.PathName = newPath;
bool ss = mapDoc.get_IsReadOnly(mapDoc.DocumentFilename);
mapDoc.Save();
报相同的错误database not found
在 ESRI.ArcGIS.Carto.MapDocumentClass.Save(Boolean bUseRelativePaths, Boolean bCreateThumnbail)
代码:
IMapDocument mapDoc = new MapDocumentClass();
mapDoc.Open(mxdPath);
IDataSourceHelperMapDocument repairment = new DataSourceHelperClass();
IWorkspaceName oldWorkspaceName = new WorkspaceNameClass();
oldWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
oldWorkspaceName.PathName = oldPath;
IWorkspaceName newWorkspaceName = new WorkspaceNameClass();
newWorkspaceName.WorkspaceFactoryProgID = "esriDataSourcesFile.ShapefileWorkspaceFactory";
newWorkspaceName.PathName = System.IO.Path.Combine(newPath, fileName);
repairment.ReplaceWorkspaceName(mapDoc, oldWorkspaceName, newWorkspaceName, true);
mapDoc.Save(true, true);
第二种方法:
IMapDocument mapDoc = new MapDocumentClass();
mapDoc.Open(mxdPath);
IMap pMap = mapDoc.get_Map(0);
ILayer pLayer = GetLayerByName(layerName, pMap);
IDataLayer dataLayer = (IDataLayer)pLayer;
IDatasetName pDsName = (IDatasetName)(dataLayer.DataSourceName);
IWorkspaceName ws = pDsName.WorkspaceName;
string path = "test2";
string newPath = System.IO.Path.Combine(folderPath, path);
ws.PathName = newPath;
bool ss = mapDoc.get_IsReadOnly(mapDoc.DocumentFilename);
mapDoc.Save();
报相同的错误database not found
3 个回复
yiliyanyu
赞同来自:
xiaosi9524 - GISER
赞同来自:
朱新颖
赞同来自:
要回复问题请先登录或注册
发起人
相关问题
问题状态