System.Runtime.InteropServices.COMException:HRESULT:0x80040228 [英] System.Runtime.InteropServices.COMException: HRESULT:0x80040228
本文介绍了System.Runtime.InteropServices.COMException:HRESULT:0x80040228的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我已经构建了一个Web服务,该服务将实现ArcTools中名为FeatureclassToCoverage的功能之一.我的代码如下:
I have built a webservice which is to realize one of the functions in ArcTools named FeatureclassToCoverage. My code is as below:
public string FeatureClassToCoverage(string string_inFeatures, string string_outCoverage) //List<string string_inFeatures>
{
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(string_inFeatures), 0);//<big>THE PROBLEM LINE</big>
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(string_inFeatures));
String outDict = System.IO.Path.GetDirectoryName(string_inFeatures);
String outCoverage = outDict + "\\" + string_outCoverage;
ESRI.ArcGIS.ConversionTools.FeatureclassToCoverage featureClassToCoverage = new FeatureclassToCoverage(pFeatureClass, outCoverage);
ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new Geoprocessor();
ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult results = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)gp.Execute(featureClassToCoverage, null);
string returnString = outCoverage;
if (results.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
{
returnString = "Changing Failed!";
}
return returnString;
}
当我测试服务时,问题显示为标题.它指向"IWorkSpace"行.
谁可以帮助我呢?谢谢!
When I test the service, the problem shows as the title. It points to the ''IWorkSpace'' line.
Who can help me with it? Thank you!
推荐答案
我自己解决了.
我只是向其中添加代码,如下所示:
I have solved it by myself.
I just add code to it as follows:
public string FeatureClassToCoverage(string string_inFeatures, string string_outCoverage) //List<string string_inFeatures>
{
<big>ESRI.ArcGIS.esriSystem.IAoInitialize ao = new ESRI.ArcGIS.esriSystem.AoInitialize();
ao.Initialize(ESRI.ArcGIS.esriSystem.esriLicenseProductCode.esriLicenseProductCodeArcInfo);</big>
IWorkspaceFactory pWorkspaceFactory = new ShapefileWorkspaceFactory();
IWorkspace pWorkspace = pWorkspaceFactory.OpenFromFile(System.IO.Path.GetDirectoryName(string_inFeatures), 0);
IFeatureWorkspace pFeatureWorkspace = pWorkspace as IFeatureWorkspace;
IFeatureClass pFeatureClass = pFeatureWorkspace.OpenFeatureClass(System.IO.Path.GetFileNameWithoutExtension(string_inFeatures));
String outDict = System.IO.Path.GetDirectoryName(string_inFeatures);
String outCoverage = outDict + "\\" + string_outCoverage;
ESRI.ArcGIS.ConversionTools.FeatureclassToCoverage featureClassToCoverage = new FeatureclassToCoverage(pFeatureClass, outCoverage);
ESRI.ArcGIS.Geoprocessor.Geoprocessor gp = new Geoprocessor();
ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult results = (ESRI.ArcGIS.Geoprocessing.IGeoProcessorResult)gp.Execute(featureClassToCoverage, null);
string returnString = outCoverage;
if (results.Status != ESRI.ArcGIS.esriSystem.esriJobStatus.esriJobSucceeded)
{
returnString = "Changing Failed!";
}
return returnString;
}
您好,
我不知道string_inFeatures
包含什么,但是无论如何,如果它是文件名,那么问题是System.IO.Path.GetDirectoryName(string_inFeatures)
返回的是目录名而不是文件路径.
您需要传递文件路径.
有关详细信息,请此处.
Hello,
I don''t know whatstring_inFeatures
contains but anyway if it is a file name then the problem is thatSystem.IO.Path.GetDirectoryName(string_inFeatures)
returns a directory name not a file path.
you need to pass a file path.
Look here for details.
这篇关于System.Runtime.InteropServices.COMException:HRESULT:0x80040228的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文