Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I need to create a dialog that the user can select a proper Workspace.

Is there a similar to IAddDataDialog, but for workspaces?

share|improve this question
up vote 11 down vote accepted

Assuming you have desktop, you can use IGxDialog.

public static IWorkspace Browse4Workspace(int hwnd)
    IGxDialog gxDlg = new GxDialogClass();
    gxDlg.ObjectFilter = new GxFilterWorkspacesClass();
    gxDlg.AllowMultiSelect = false;
    IEnumGxObject workspaces;
    IWorkspace ws = null;
    if (gxDlg.DoModalOpen(hwnd, out workspaces) && workspaces != null)
        IGxObject gxObj = workspaces.Next();
        if (gxObj is IGxDatabase)
            IGxDatabase gxDB = gxObj as IGxDatabase;
            if (gxDB != null)
                ws = gxDB.Workspace;
        else if (gxObj is IGxFolder)
            //Todo: figure out how to decide which workspace to get for
            // a particular folder (shapefile, raster etc.)                    
            //IEnumName enumName = ((IGxFolder)gxObj).FileSystemWorkspaceNames;

            // for now just assume we want a shapefile ...
            IWorkspaceFactory wsf = new ESRI.ArcGIS.DataSourcesFile.ShapefileWorkspaceFactoryClass();
            ws = wsf.OpenFromFile(((IGxFile)gxObj).Path, hwnd);
    return ws;

private void testToolStripMenuItem_Click(object sender, EventArgs e)
        IWorkspace ws = Browse4Workspace(this.Handle.ToInt32());
        if (ws != null)
            MessageBox.Show(this, ws.PathName);
            MessageBox.Show(this, "no workspace selected");
    catch (Exception ex)
        MessageBox.Show(this, ex.Message);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.