I would like to know what is the easiest way to set the starting location of a data dialog to a IWorkspace?

My problem is that basically I do not want a connection (.sde file) for the users. I want to set the starting location to a workspace connected via IPropertySet. Is it possible?

This is related: Force a new AddDataDialog to open at a defined directory path but does not help.


following Kirk's suggestion, here's a code snippet. This does not work.

    public static IDataset OpenDatasetDialog(IWorkspace workspace,int handle)
        var workspaceName = (IWorkspaceName)((IDataset)workspace).FullName);
        var gxDatabase = new GxdatabaseClass();
        gxDatabase.WorkspaceName = workspaceName;

        // we need to set a different variable as .NET runtime does not allow ref parameters with casts
        object gxObj = (object)gxDatabase;

        IGxDialog openDialog = new GxDialogClass();
        openDialog.RememberLocation = false;
        openDialog.set_StartingLocation(ref gxObj);
        var filterColletion = (IGxObjectFilterCollection)openDialog;
        filterColletion.AddFilter(new GxFilterTablesAndFeatureClassesClass(), true);
        openDialog.AllowMultiSelect = false;
        IEnumGxObject datasets = null;
        IDataset dataset = null;

        if (openDialog.DoModalOpen(0, out datasets) && datasets != null)
            IGxObject gxObject = datasets.Next();
            if (gxObject is IGxDataset)
                IGxDataset gxDataset = (IGxDataset)gxObject;
                dataset = gxDataset.Dataset;
                throw new ArgumentException();
        return dataset;

2 Answers 2


Kirk's answer is on the right track. The only thing missing is properly adding the GxDatabase into the dialog's internal catalog tree.

See the code below. The OpenGxDialogForRemoteWorkspace returns an enumerable of selected objects (if multiselect is allowed) or null in case the dialog is cancelled. It's very basic since I omitted the object filters you used, but I think you get the idea.

    private static IEnumerable<IGxObject> OpenGxDialogForRemoteWorkspace(IWorkspaceName workspaceName, int handle)
        if (workspaceName == null) throw new ArgumentNullException("workspaceName");
        if (workspaceName.Type != esriWorkspaceType.esriRemoteDatabaseWorkspace)
            throw new ArgumentException("Remote worskpace is expected.", "workspaceName");

        var gxDatabase = new GxDatabaseClass();
        gxDatabase.WorkspaceName = workspaceName;

        var gxDialog = new GxDialogClass();
        var catalog = gxDialog.InternalCatalog;

        var topLevelCatalogItems = AsEnumerable(((IGxObjectContainer)catalog).Children);
        var remoteDatabaseFolder = topLevelCatalogItems.OfType<IGxRemoteContainer>().First();


        gxDialog.RememberLocation = false;

        object gxDatabaseObject = gxDatabase;
        gxDialog.set_StartingLocation(ref gxDatabaseObject);

        IEnumGxObject selection;
        if (gxDialog.DoModalOpen(handle, out selection))
            return selection != null ? AsEnumerable(selection) : null;

        return null;

    private static IEnumerable<IGxObject> AsEnumerable(IEnumGxObject enumGxObject)
        if (enumGxObject == null) throw new ArgumentNullException("enumGxObject");

        IGxObject gxObject;
        while ((gxObject = enumGxObject.Next()) != null)
            yield return gxObject;
  • is there a way to split the points between two answers? @KirkKuykendall was right on the spot, but Petr Krebs killed it. Thanks to both of you guys! How did learn to do that? Where is the docs that you guys are using? :P Dec 22, 2011 at 16:07

The doc for IGxDialog.StartingLocation says:

The dialog's starting location. This can be an IGxObject or a text-string containing the full name of an object.

I would interpret that to mean you could create an IWorkspaceName using your propertyset, then create a new GxDatabase object and set IGxDatabase.Workspacename to the workspacename, and finally assign the IGxDatabase to IGxDialog.StartingLocation.

  • oooh, kirk knows all. I have little experience with the gx classes and did not know the proper way to do it. I'll try it. thanks kirk! Dec 21, 2011 at 17:55
  • This approach, compiles and runs, but the dialog does not honor the starting location configuration. Dec 21, 2011 at 19:31
  • I've also tried setting this as a GxObject, but does not work also. Dec 21, 2011 at 20:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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