How do I create a layer package programmatically with ArcObjects (via ArcEngine.Net)?

1039
2
12-12-2013 08:41 AM
TimB
by
New Contributor III
I am trying to create a layer package programmatically with an ArcEngine (.Net) application.  The documentation has good information on how to open a package here: http://help.arcgis.com/en/sdk/10.0/Arcobjects_net/conceptualhelp/index.html#//000100000nv8000000.  However, I can't find ANYTHING anywhere showing how to create a layer package. 

My thought was to use the PackageLayer_management call from a geoprocessor object, but I can not get that to work either.  Here is my code for a simple test (I've tried multiple variations with no luck).  I am starting to wonder if PackageLayer_management is even available to ArcEngine.  I am using other ArcToolbox calls following a similiar approach to that below and those work fine.  Any suggestions/examples would be greatly appreciated. 

        public void CreatePackageLayerTest(ILayer SourceLayer, string outputFile, string GeoDBAbsFileName)
        {

            _geoProcessor.SetEnvironmentValue("Workspace", GeoDBAbsFileName);
            _gpParams.Add(SourceLayer);
            _gpParams.Add(outputFile);
            _gpParams.Add("CONVERT");

            try
            {
                _geoProcessor.Execute("PackageLayer_management", _gpParams, null);
            }
            catch (Exception ex)
            {
                MessageBox.Show("There was a GeoProcessing Error." + ex.ToString());
                returnMessages(_geoProcessor);
            }

            _gpParams.RemoveAll();

        }
0 Kudos
2 Replies
DuncanHornby
MVP Notable Contributor
Tim,

I believe the way you are doing it is the best way, calling the geo-processing tool. Have you tried running the geo-processing package layer tool on the layer from ArcMap? If you do and its some dataset you had just loaded into ArcMap then you get a 001115 error which states you have not set the description. I suspect this is your problem, you need to set a description for the layer before you can package it up.

You can use the interface ILayerGeneralProperties to alter this.

Duncan
0 Kudos
HagenProbsthain1
New Contributor III

Hi, I try the same, but I always get a "HRESULT E_Fail-Error" if I give the reference of the layer as SourceLayer. It works only with the layername (as string). What can I do? I don't want to use the layernames, because they are not unique. Here is the code (VB.NET):

Friend Sub SaveAsLayerpackage(ByVal pLayer As ESRI.ArcGIS.Carto.ILayer, _
                              ByVal pOutPkgfilename As String)

   Dim GP As New ESRI.ArcGIS.Geoprocessor.Geoprocessor

   Dim pkgTool As New ESRI.ArcGIS.DataManagementTools.PackageLayer

   'this works:

   pkgTool.in_layer = pLayer.Name

   'this don't work:
   pkgTool.in_layer = pLayer


   pkgTool.output_file = pOutPkgfilename

   GP.Execute(pkgTool, Nothing)

End Sub

Hagen

0 Kudos