private void AddTable(string strPath,string strFileName)
        {
            try
            {

                IWorkspaceFactory pFact = new TextFileWorkspaceFactory();
                IWorkspace pWorkspace = pFact.OpenFromFile(strPath, 0);
                IFeatureWorkspace pFeatws = pWorkspace as IFeatureWorkspace;
                ITable ptable = pFeatws.OpenTable(strFileName);

                IMxDocument pmxdoc = ArcMap.Document as IMxDocument;
                IMap pmap = pmxdoc.FocusMap;

                IStandaloneTable pStTab = new StandaloneTableClass();
                pStTab.Table = ptable;
                IStandaloneTableCollection pStTabColl = pmap as IStandaloneTableCollection;
                pStTabColl.AddStandaloneTable(pStTab);
                pmxdoc.UpdateContents();

                ITableWindow2 ptableWindow = new TableWindowClass();
                ptableWindow.Application = ArcMap.Application ;
                ptableWindow.StandaloneTable = pStTab;

                ptableWindow.Show(true);

                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFact);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pWorkspace);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatws);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(ptable);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pStTab);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pStTabColl);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(ptableWindow);

                GC.Collect();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        private void AddTable(string strPath, string strFileName)
        {
            try
            {
                IWorkspaceFactory pFact      = new TextFileWorkspaceFactory();
                IWorkspace        pWorkspace = pFact.OpenFromFile(strPath, 0);
                IFeatureWorkspace pFeatws    = pWorkspace as IFeatureWorkspace;
                ITable            ptable     = pFeatws.OpenTable(strFileName);

                IMxDocument pmxdoc = ArcMap.Document as IMxDocument;
                IMap        pmap   = pmxdoc.FocusMap;

                IStandaloneTable pStTab = new StandaloneTableClass();
                pStTab.Table = ptable;
                IStandaloneTableCollection pStTabColl = pmap as IStandaloneTableCollection;
                pStTabColl.AddStandaloneTable(pStTab);
                pmxdoc.UpdateContents();

                ITableWindow2 ptableWindow = new TableWindowClass();
                ptableWindow.Application     = ArcMap.Application;
                ptableWindow.StandaloneTable = pStTab;

                ptableWindow.Show(true);

                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFact);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pWorkspace);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pFeatws);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(ptable);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pStTab);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(pStTabColl);
                System.Runtime.InteropServices.Marshal.ReleaseComObject(ptableWindow);

                GC.Collect();
            }

            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        public IWorkspaceFactory GetWorkspaceFactory(string aFilePath, bool aTextFile = false, bool Messages = false)
        {
            // This function decides what type of feature workspace factory would be best for this file.
            // it is up to the user to decide whether the file path and file names exist (or should exist).

            // Reworked 18/05/2016 to deal with the singleton issue.

            IWorkspaceFactory pWSF;
            // What type of output file it it? This defines what kind of workspace factory will be returned.
            if (aFilePath.Substring(aFilePath.Length - 4, 4) == ".gdb")
            {
                // It is a file geodatabase file.
                Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.FileGDBWorkspaceFactory");
                System.Object obj = Activator.CreateInstance(t);
                pWSF = obj as IWorkspaceFactory;
            }
            else if (aFilePath.Substring(aFilePath.Length - 4, 4) == ".mdb")
            {
                // Personal geodatabase.
                Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.AccessWorkspaceFactory");
                System.Object obj = Activator.CreateInstance(t);
                pWSF = obj as IWorkspaceFactory;
            }
            else if (aFilePath.Substring(aFilePath.Length - 4, 4) == ".sde")
            {
                // ArcSDE connection
                Type t = Type.GetTypeFromProgID("esriDataSourcesGDB.SdeWorkspaceFactory");
                System.Object obj = Activator.CreateInstance(t);
                pWSF = obj as IWorkspaceFactory;
            }
            else if (aTextFile == true)
            {
                // Text file
                //Type t = Type.GetTypeFromProgID("esriDataSourcesOleDB.TextFileWorkspaceFactory");
                //System.Object obj = Activator.CreateInstance(t);
                pWSF = new TextFileWorkspaceFactory();
            }
            else // Shapefile
            {
                Type t = Type.GetTypeFromProgID("esriDataSourcesFile.ShapefileWorkspaceFactory");
                System.Object obj = Activator.CreateInstance(t);
                pWSF = obj as IWorkspaceFactory;
            }
            return pWSF;
        }