// Create the file geodatabase. public static void CreateFileGeodatabase() { string strFgdPath = @"C:\temp\"; //string strFgdName = @"AddressCrossCheck"; string strFgdName = fileGeodatabaseName; IWorkspaceName workspaceName = null; // Instantiate a file geodatabase workspace factory and create a new file geodatabase. // The Create method returns a workspace name object. IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass(); Console.WriteLine("Creating File Geodatabase..."); // check if file geodatabase exists, before creating it if (!(workspaceFactory.IsWorkspace(strFgdPath + strFgdName + ".gdb"))) { workspaceName = workspaceFactory.Create(strFgdPath, strFgdName, null, 0); } else { IFileNames arcFileNames = new FileNames(); arcFileNames.Add(strFgdPath + strFgdName + ".gdb"); workspaceName = workspaceFactory.GetWorkspaceName(strFgdPath, arcFileNames); } // Cast the workspace name object to the IName interface and open the workspace. var name = (IName)workspaceName; workspaceFGDB = (IWorkspace)name.Open(); // Load the data. ImportDataToFGDB(); }
// create a file geodatabase in user-specified location #region "Create FileGeodatabase" public static IWorkspace CreateFileGdbWorkspace(string strFgdPath, string strFgdName) { IWorkspaceName workspaceName = null; // Instantiate a file geodatabase workspace factory and create a new file geodatabase. // The Create method returns a workspace name object. IWorkspaceFactory workspaceFactory = new FileGDBWorkspaceFactoryClass() as IWorkspaceFactory; // check if file geodatabase exists, before creating it if (!(workspaceFactory.IsWorkspace(strFgdPath + strFgdName))) { workspaceName = workspaceFactory.Create(strFgdPath, strFgdName, null, 0); } else { IFileNames arcFileNames = new FileNames(); arcFileNames.Add(strFgdPath + strFgdName); workspaceName = workspaceFactory.GetWorkspaceName(strFgdPath, arcFileNames); } // Cast the workspace name object to the IName interface and open the workspace. IName name = (IName)workspaceName; IWorkspace workspace = (IWorkspace)name.Open(); return(workspace); }