c#+AE——异常来自 HRESULT:0x80040351

导出shp文件出错,异常HRESULT:0x80040351

原因是后缀名重复。之前没有标记的那句。保存后的文件后缀名出现 ***.shp.shp  

删除多余后缀名即可。


代码如下


private void 导出数据ToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialog m_save = new SaveFileDialog();
            m_save.Filter = "SHP(*.shp)|*.shp|tiff(*.tif)|*.tif";
            DialogResult diaR = m_save.ShowDialog();
            if (diaR == DialogResult.OK)
            {
                string Outpath = m_save.FileName;
                if (m_save.FileName.EndsWith(".tif"))
                {                  
                    ILayer rLayer2 = LayerMenu.Tag as ILayer;
                    IRaster resultDataset = (rLayer2 as IRasterLayer).Raster as IRaster;

                    IWorkspaceFactory pWKSF = new RasterWorkspaceFactory();
                    
                    ISaveAs pSaveAs = resultDataset as ISaveAs;
                    pSaveAs.SaveAs(Outpath, null, "TIFF");//以tif格式保存
                }
                if (m_save.FileName.EndsWith(".shp"))  //导出为shp文件
                {
                    Outpath = Outpath.Remove(Outpath.LastIndexOf("."));//删除多余后缀名
                    ILayer iLayer = LayerMenu.Tag as ILayer;
                    IFeatureLayer pFeatureLayer = iLayer as IFeatureLayer;
                    IFeatureClass pFeatureClass = pFeatureLayer.FeatureClass;

                        string sFileName = System.IO.Path.GetFileName(Outpath);
                        string sFilePath = System.IO.Path.GetDirectoryName(Outpath);

                        IDataset pDataset = pFeatureClass as IDataset;
                        IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactoryClass();
                        IFeatureWorkspace pFeatureWorkspace = pWorkspaceFactory.OpenFromFile(sFilePath, 0) as IFeatureWorkspace;
                        IWorkspace pWorkspace = pFeatureWorkspace as IWorkspace;
                        pDataset.Copy(sFileName, pFeatureWorkspace as IWorkspace);
                    }
            }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值