[GIS] Connecting to Folder/File to open mxd document using ArcObjects

arcobjects

I have a dialog box written in ArcObjects.

I am programming the Map button on the dialog box.

The user picks a type of station and county.

The program goes to folder containing the mxds and opens the one with the same county name.

I need to know how to code for going to folder and then opening the mxd.

My program is listed below :

Dim pWorkspaceName As WorkspaceName
Set pWorkspaceName = New WorkspaceName
Dim pWorkspaceName2 As WorkspaceName2
Set pWorkspaceName2 = New WorkspaceName2
pWorkspaceName.PathName = "K:\TASS\4_MAPPING_DATA_Maps\2012"
pWorkspaceName.PathName2 = "K:\TASS\4_MAPPING_DATA_SUPPORT\Traffic_Mapping\Urban_Maps"

Dim cboStations As String
If cboStations = "Annual" Then pWorkspaceName.PathName
Else
pWorkspaceName.PathName2


Dim districts As String
Dim cboDistrict As String

If cboDistrict = "Abilene" Then Application.OpenDocument ("K:\TASS\4_MAPPING\Abilene_Base_Map.mxd")
Elif
cboDistrict = "Amarillo" then getmxd "K:\TASS\4_ps\2012\Amarillo"

Best Answer

There is a code for Open New Map Document. You can go through this. But it did not work for me.

I have done following code for me. I have no idea about VB. So, I am posting this code in c#. I hope you can convert it for yourself.

void OpenMxd(string mxdPath)
{
    IMapDocument mapDoc = new MapDocumentClass();
    if (mapDoc.IsPresent[mxdPath] && mapDoc.IsMapDocument[mxdPath] && !mapDoc.IsPasswordProtected[mxdPath])
    {
        mapDoc.Open(mxdPath);
        IMap map = mapDoc.Map[0];
        ArcMap.Document.ActiveView = map as IActiveView;
        mapDoc.Close();
    }
}
Related Question