ArcMapAddinDistanceAndDirection.Models.FeatureClassUtils.CreateFCOutput C# (CSharp) Method

CreateFCOutput() public method

Creates the output featureclass, either fgdb featureclass or a shapefile
public CreateFCOutput ( string outputPath, SaveAsType saveAsType, List graphicsList, ISpatialReference ipSpatialRef ) : IFeatureClass
outputPath string location of featureclass
saveAsType SaveAsType Type of output selected, either fgdb featureclass or shapefile
graphicsList List List of graphics for selected tab
ipSpatialRef ISpatialReference Spatial Reference being used
return IFeatureClass
        public IFeatureClass CreateFCOutput(string outputPath, SaveAsType saveAsType, List<Graphic> graphicsList, ISpatialReference ipSpatialRef)
        {
            string fcName = System.IO.Path.GetFileName(outputPath);
            string folderName = System.IO.Path.GetDirectoryName(outputPath);
            IFeatureClass fc = null;

            try
            {
                if (saveAsType == SaveAsType.FileGDB)
                {
                    IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactory();
                    IWorkspace workspace = workspaceFactory.OpenFromFile(folderName, 0);
                    IFeatureWorkspace fWorkspace = (IFeatureWorkspace)workspace;

                    if (DoesFeatureClassExist(folderName, fcName))
                    {
                        DeleteFeatureClass(fWorkspace, fcName);
                    }

                    fc = CreatePolylineFeatureClass(fWorkspace, fcName);

                    foreach (Graphic graphic in graphicsList)
                    {
                        IFeature feature = fc.CreateFeature();

                        feature.Shape = graphic.Geometry;
                        feature.Store();
                    }

                }
                else if (saveAsType == SaveAsType.Shapefile)
                {
                    // already asked them for confirmation to overwrite file
                    if (File.Exists(outputPath))
                    {
                        DeleteShapeFile(outputPath);
                    }            

                    fc = ExportToShapefile(outputPath, graphicsList, ipSpatialRef);
                }
                return fc;
            }
            catch (Exception ex)
            {
                return fc;
            }
        }