AnsweredAssumed Answered

Deleting FGDB

Question asked by saurabh18.cs on Oct 22, 2015
Latest reply on Sep 7, 2016 by rastrauch

G'Day Everyone,

 

I am facing issues on deleting fgdb, scenario is like this :

 

" i have created fgdb programatically and loaded to TOC of ArcMap, after completion of work i want TOC to be clear and fgdb to be deleted but it is throwing an error"

 

The reason behind error is that fgdb is not released since arcmap is not closed. how to overcome this issue?

 

i am using following code to delete , please suggest

 

if (IO.Directory.Exists(iPLANConstants.strLSFGDBKeyPath + @"\" + clsLandSafeguarding.strDraftNameGlobal + ".gdb"))

                {

                    ArcMap.Document.FocusMap.ClearLayers();

                    ArcMap.Document.ActiveView.ContentsChanged();

                    ArcMap.Document.ActiveView.Refresh();

 

          string toolboxLoc = iPLANConstants.Instance.appconfig["dmtbx"].ToString();

            try

            {

                Geoprocessor gpProcess = new Geoprocessor();

                IGeoProcessor2 gp = new GeoProcessorClass();

 

 

                IVariantArray parameters = new VarArray();

                parameters.Add(iPLANConstants.strLSFGDBKeyPath + @"\" + clsLandSafeguarding.strDraftNameGlobal + ".gdb");

                try

                {

                   

                        gp.AddToolbox(toolboxLoc); // toolboxLox is correct

                        gp.Execute("Delete_management", parameters, null);

                        gp.RemoveToolbox(toolboxLoc);

                        log.Info(gp.GetMessage(0));

                        gp.ClearMessages();

                        gp = null;

                  

                }

                catch (Exception gpEx)

                {

                   

                }

 

Also tried below options but no success in deleting but no error also

string[] lockfiles = Directory.GetFiles(FileGDBLoc, "*.lock");

 

 

                        if (lockfiles.Length > 0)

                        {

                            //OPTION1

                            //ESRI.ArcGIS.DataManagementTools.Compact compactProcess = new ESRI.ArcGIS.DataManagementTools.Compact();

 

 

                            //compactProcess.in_workspace = FileGDBLoc;

 

 

                            //gpProcess.Execute(compactProcess as IGPProcess, null);

 

 

                            //OPTION2

                            //FileGDBWorkspaceFactory pWorkspaceFactory = default(FileGDBWorkspaceFactory);

                            //IWorkspace pWorkspace = default(IWorkspace);

                            //pWorkspaceFactory = new ESRI.ArcGIS.DataSourcesGDB.FileGDBWorkspaceFactory();

                            //pWorkspace = pWorkspaceFactory.OpenFromFile(FileGDBLoc, 0);

                            //IDatabaseCompact databaseCompact;

                            //if (typeof(ESRI.ArcGIS.Geodatabase.IDatabaseCompact) == pWorkspace)

                            //{

                            //    databaseCompact = (IDatabaseCompact)pWorkspace;

                            //    if (databaseCompact.CanCompact())

                            //    {

                            //        databaseCompact.Compact();

                            //    }

                            //}

                            //else

                            //{

                            //    Console.WriteLine("The workspace does not support IDatabaseCompact");

                            //}

                        }

Outcomes