private void ExportTable2DBF(ITable ptable, string strPath, string strFilename) { IDataset pDataset = ptable as IDataset; IDatasetName pDatasetName = pDataset.FullName as IDatasetName; IWorkspaceFactory pWF = new ShapefileWorkspaceFactory(); IWorkspace pWorkspace = pWF.OpenFromFile(strPath, 0); IDataset pDatasetOUT = pWorkspace as IDataset; IWorkspaceName pWorkspaceName = pDatasetOUT.FullName as IWorkspaceName; IDatasetName pOUTDatasetName = new TableNameClass(); pOUTDatasetName.Name = strFilename; pOUTDatasetName.WorkspaceName = pWorkspaceName; IExportOperation pExpOp = new ExportOperationClass(); pExpOp.ExportTable(pDatasetName, null, null, pOUTDatasetName, 0); }
/// <summary> /// Exports a dbf file to a designated place from a layer /// </summary> /// <param name="sOutputLocation">The location to create the dbf</param> /// <param name="pFLayer">the Featue layer from which to export the data</param> /// <returns>string - the name of the exported dbf (without the extension)</returns> /// <notes> /// Modified from Kirk Kuykendall's code from this post /// http://forums.esri.com/Thread.asp?c=93&f=993&t=210767&mc=12#msgid652601 /// </notes> /// <changelog> /// comments created. /// /// </changelog> public string createDBF(string sOutputLocation, IFeatureLayer pFLayer) { if (pFLayer == null) { MessageBox.Show("Feature layer was not found"); return(""); } try { ITable pTable = (ITable)pFLayer.FeatureClass; IDataset pDs = (IDataset)pTable; IDatasetName pDsName = (IDatasetName)pDs.FullName; IWorkspaceFactory pWkSpFact = new ShapefileWorkspaceFactoryClass(); IWorkspace pWkSp = pWkSpFact.OpenFromFile(sOutputLocation, 0); IDataset pWkSpDs = (IDataset)pWkSp; IWorkspaceName pWkSpName = (IWorkspaceName)pWkSpDs.FullName; IDatasetName pOutDsName = new TableNameClass(); pOutDsName.Name = pDs.Name + "_" + DateTime.UtcNow.DayOfYear + DateTime.UtcNow.Hour + DateTime.UtcNow.Minute + DateTime.UtcNow.Second; //pOutDsName.Name = pDs.Name; pOutDsName.WorkspaceName = pWkSpName; IExportOperation pExpOp = new ExportOperationClass(); pExpOp.ExportTable(pDsName, null, null, pOutDsName, 0); return(pOutDsName.Name); } catch (Exception ex) { MessageBox.Show("Errors occurred: \r\n\r\n" + ex.Message); return(null); } finally { } }
private void ExportTable2DBF(ITable ptable, string strPath, string strFilename) { IDataset pDataset = ptable as IDataset; IDatasetName pDatasetName = pDataset.FullName as IDatasetName; IWorkspaceFactory pWF = new ShapefileWorkspaceFactory(); IWorkspace pWorkspace = pWF.OpenFromFile(strPath, 0); IDataset pDatasetOUT = pWorkspace as IDataset; IWorkspaceName pWorkspaceName = pDatasetOUT.FullName as IWorkspaceName; IDatasetName pOUTDatasetName = new TableNameClass (); pOUTDatasetName.Name = strFilename; pOUTDatasetName.WorkspaceName = pWorkspaceName; IExportOperation pExpOp = new ExportOperationClass(); pExpOp.ExportTable(pDatasetName, null, null, pOUTDatasetName, 0); }