Example #1
0
        /// <summary>
        /// 创建新的PersonalGeodatabase
        /// </summary>
        /// <param name="ParentDirectory">创建MDB路径</param>
        /// <param name="strName">MDB名称</param>
        public static bool CreatePGDB(string ParentDirectory, string strName)
        {
            IWorkspace Ws = null;

            try
            {
                IWorkspaceFactory2 workspaceFactory = (IWorkspaceFactory2) new AccessWorkspaceFactoryClass();
                string             strFilePath      = ParentDirectory + strName;
                if (System.IO.File.Exists(strFilePath))
                {
                    System.IO.File.Delete(strFilePath);
                }
                IWorkspaceName workspacename    = workspaceFactory.Create(ParentDirectory, strName, null, 0);
                string         connectionstring = "DATABASE=" + workspacename.PathName;
                Ws = workspaceFactory.OpenFromString(connectionstring, 0);
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return(false);
            }
            finally
            {
                if (Ws != null)
                {
                    Marshal.ReleaseComObject(Ws);
                    Ws = null;
                }
            }
            return(true);
        }
Example #2
0
        /// <summary>
        /// 创建新的FileGeodatabase
        /// </summary>
        /// <param name="ParentDirectory">创建FGDB路径</param>
        /// <param name="strName">FGDB名称</param>
        public static bool CreateFGDB(string ParentDirectory, string strName, ref IWorkspace ws)
        {
            IWorkspace ipWks = null;

            try
            {
                IWorkspaceFactory2 workspaceFactory = (IWorkspaceFactory2) new FileGDBWorkspaceFactoryClass();
                string             strFilePath      = ParentDirectory + "\\" + strName;
                if (System.IO.Directory.Exists(strFilePath))
                {
                    System.IO.Directory.Delete(strFilePath, true);
                }

                IWorkspaceName workspacename = workspaceFactory.Create(ParentDirectory, strName, null, 0);
                ipWks = ((IName)workspacename).Open() as IWorkspace;
                ws    = ipWks;
            }
            catch (Exception exp)
            {
                Hy.Common.Utility.Log.OperationalLogManager.AppendMessage(exp.ToString());

                return(false);
            }
            return(true);
        }