Any extention Open File Dialog The Next CEO of Stack OverflowOpening geodatabase files using Browse Dialog Command (VB.NET/C#) of ArcObjects?Data dialog to select GeodatabaseArcObjects: How to get the size of the formatted text part only of a TextElement whose text contains formatting tags?Checkout Spatial Analyst extention, ArcObjects codeExploring ArcObjects through C# or VB from Python backgroundOverride default ArcMap editing error dialogConnecting to Folder/File to open mxd document using ArcObjects?Can't open Dgn file with CadWorkspaceFactory?Getting FeatureTemplate dialog form ArcObjects?Selecting Workspace and Datasets from same dialog using ArcObjects?What file did esriControls.ControlsOpenDocCommand open?

What connection does MS Office have to Netscape Navigator?

How to start emacs in "nothing" mode (`fundamental-mode`)

Limits on contract work without pre-agreed price/contract (UK)

What does convergence in distribution "in the Gromov–Hausdorff" sense mean?

Help understanding this unsettling image of Titan, Epimetheus, and Saturn's rings?

Is it possible to search for a directory/file combination?

What is the result of assigning to std::vector<T>::begin()?

Example of a Mathematician/Physicist whose Other Publications during their PhD eclipsed their PhD Thesis

How to invert MapIndexed on a ragged structure? How to construct a tree from rules?

If a black hole is created from light, can this black hole then move at speed of light?

Anatomically Correct Strange Women In Ponds Distributing Swords

multiple labels for a single equation

Does it take more energy to get to Venus or to Mars?

If/When UK leaves the EU, can a future goverment conduct a referendum to join the EU?

Why didn't Khan get resurrected in the Genesis Explosion?

How did the Bene Gesserit know how to make a Kwisatz Haderach?

How do scammers retract money, while you can’t?

Are there any unintended negative consequences to allowing PCs to gain multiple levels at once in a short milestone-XP game?

What is the purpose of the Evocation wizard's Potent Cantrip feature?

How do I transpose the 1st and -1th levels of an arbitrarily nested array?

Bold, vivid family

Written every which way

What happens if you roll doubles 3 times then land on "Go to jail?"

Would this house-rule that treats advantage as a +1 to the roll instead (and disadvantage as -1) and allows them to stack be balanced?



Any extention Open File Dialog



The Next CEO of Stack OverflowOpening geodatabase files using Browse Dialog Command (VB.NET/C#) of ArcObjects?Data dialog to select GeodatabaseArcObjects: How to get the size of the formatted text part only of a TextElement whose text contains formatting tags?Checkout Spatial Analyst extention, ArcObjects codeExploring ArcObjects through C# or VB from Python backgroundOverride default ArcMap editing error dialogConnecting to Folder/File to open mxd document using ArcObjects?Can't open Dgn file with CadWorkspaceFactory?Getting FeatureTemplate dialog form ArcObjects?Selecting Workspace and Datasets from same dialog using ArcObjects?What file did esriControls.ControlsOpenDocCommand open?










1















GetOpenFilename doesn't work in arcobjects VBA, so I have to use pGxDialog.



Standard pGxDialog doesn't let to open any file I want, a few extentions are available only (shp, dxf, xls...).



Maybe, I just don't know how to set a Filter.



I don't need to open extra extension files for reading/writing, I just need to return the PATH of the document to a variable, which will be used later on in the code.



I scripting in VBA, arcgis 10.2.2










share|improve this question
























  • Please edit the Question to clearly state your question (ending in a question mark)

    – Vince
    Dec 7 '15 at 19:34















1















GetOpenFilename doesn't work in arcobjects VBA, so I have to use pGxDialog.



Standard pGxDialog doesn't let to open any file I want, a few extentions are available only (shp, dxf, xls...).



Maybe, I just don't know how to set a Filter.



I don't need to open extra extension files for reading/writing, I just need to return the PATH of the document to a variable, which will be used later on in the code.



I scripting in VBA, arcgis 10.2.2










share|improve this question
























  • Please edit the Question to clearly state your question (ending in a question mark)

    – Vince
    Dec 7 '15 at 19:34













1












1








1








GetOpenFilename doesn't work in arcobjects VBA, so I have to use pGxDialog.



Standard pGxDialog doesn't let to open any file I want, a few extentions are available only (shp, dxf, xls...).



Maybe, I just don't know how to set a Filter.



I don't need to open extra extension files for reading/writing, I just need to return the PATH of the document to a variable, which will be used later on in the code.



I scripting in VBA, arcgis 10.2.2










share|improve this question
















GetOpenFilename doesn't work in arcobjects VBA, so I have to use pGxDialog.



Standard pGxDialog doesn't let to open any file I want, a few extentions are available only (shp, dxf, xls...).



Maybe, I just don't know how to set a Filter.



I don't need to open extra extension files for reading/writing, I just need to return the PATH of the document to a variable, which will be used later on in the code.



I scripting in VBA, arcgis 10.2.2







arcgis-10.2 arcobjects vba






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Dec 7 '15 at 20:55









Hornbydd

27k32957




27k32957










asked Dec 7 '15 at 19:22









AlexAlex

999




999












  • Please edit the Question to clearly state your question (ending in a question mark)

    – Vince
    Dec 7 '15 at 19:34

















  • Please edit the Question to clearly state your question (ending in a question mark)

    – Vince
    Dec 7 '15 at 19:34
















Please edit the Question to clearly state your question (ending in a question mark)

– Vince
Dec 7 '15 at 19:34





Please edit the Question to clearly state your question (ending in a question mark)

– Vince
Dec 7 '15 at 19:34










4 Answers
4






active

oldest

votes


















1














You can call directly COM object dll



Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

Private Type OPENFILENAME
lStructSize As Long
hwndOwner As Long
hInstance As Long
lpstrFilter As String
lpstrCustomFilter As String
nMaxCustFilter As Long
nFilterIndex As Long
lpstrFile As String
nMaxFile As Long
lpstrFileTitle As String
nMaxFileTitle As Long
lpstrInitialDir As String
lpstrTitle As String
flags As Long
nFileOffset As Integer
nFileExtension As Integer
lpstrDefExt As String
lCustData As Long
lpfnHook As Long
lpTemplateName As String
End Type

Function f_OpenFileName(Titre As String) As String
'Function for select file
Dim OpenFile As OPENFILENAME
Dim lReturn As Long
Dim sFilter As String

OpenFile.lStructSize = Len(OpenFile)

'Filter
sFilter = "prj" & Chr(0) & "*.prj" & Chr(0) & Chr(0)
OpenFile.lpstrFilter = sFilter
OpenFile.nFilterIndex = 1
OpenFile.lpstrFile = String(257, 0)
OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
OpenFile.lpstrFileTitle = OpenFile.lpstrFile
OpenFile.nMaxFileTitle = OpenFile.nMaxFile

' default path
OpenFile.lpstrInitialDir = "c:"

'Title
OpenFile.lpstrTitle = Titre
OpenFile.flags = 0
lReturn = GetOpenFileName(OpenFile)

If lReturn = 0 Then
'message
f_OpenFileName = 0
Else
f_OpenFileName = Trim(OpenFile.lpstrFile)
End If
End Function


use function:



Dim txtSelectFile As String
path = f_OpenFileName( "Select a file" )





share|improve this answer

























  • @Alex for your information, all vba code exist in Arcgis v9. You can import dll as reference or call as previous method. In addition VBA is depreciated and will disappear. I suggest you to migrate your code to VB.NET solution or start new development with python.

    – GeoStoneMarten
    Dec 8 '15 at 10:16











  • thanks for information. I heard about VBA disappearing. I'm intending to learn how to make add-ins in VisualStudio in vb.net. I think it's a good idea and hope this way of arcGIS developing won't disappear too.

    – Alex
    Dec 8 '15 at 12:00


















2














This is substantially the work of Radar in an answer to a similar question, using the same ArcObjects as Hornbydd does.



I have modified Radar's function for my clients to select a delimited text file then this function returns both the path to the selected file and the file name. This fulfills Alex's request for "...return the PATH of the document to a variable"



I trimmed it down a little so it uses just core ArcObjects libraries.



Public Function BrowseForTextFile(ByVal sTitle As String, ByRef sFolder As String, ByRef sName As String) As Boolean
'Source: Radar https://gis.stackexchange.com/questions/9000/opening-geodatabase-files-using-browse-dialog-command-vb-net-c-of-arcobjects
Dim pGxDialog As IGxDialog = New GxDialog
Dim pGxObjectFilter As IGxObjectFilter = New ESRI.ArcGIS.Catalog.GxFilterTextFiles()

Dim pFilterCol As IGxObjectFilterCollection
Dim pEnumGx As IEnumGxObject
Dim pGxObject As IGxObject

sFolder = ""
sName = ""

pFilterCol = pGxDialog
pFilterCol.AddFilter(pGxObjectFilter, True)
pGxDialog.RememberLocation = True
pGxDialog.AllowMultiSelect = False
pGxDialog.Title = sTitle


If pGxDialog.DoModalOpen(0, pEnumGx) Then
pGxObject = pEnumGx.Next
sName = pGxObject.Name
sFolder = pGxObject.Parent.FullName

Return True
End If

End Function


You can call this with



Imports ESRI.ArcGIS.Catalog 'for IGxObjectFilter
Imports ESRI.ArcGIS.CatalogUI 'for IGXdialog

Friend m_sFilePathName As String
'...snipped
Dim sCSVPath As String
Dim sCSVName As String
If BrowseForTextFile("Choose a text file to load", sCSVPath, sCSVName) Then
m_sFilePathName = sCSVPath & "" & sCSVName
MsgBox("The file you chose was " & m_sFilePathName,MsgBoxStyle.Information, "Result")
Else
'Nothing chosen, Abort
Exit Sub
End If


In this case I all I want shown in the dialog is delimited text files, so I use 'GxObjectFilter' of 'GxFilterTextFiles'. You could specify 'GxFilterFiles' if you just want to be able to select "any file"



There are also scores upon scores of coclasses and classes for every object in ArcCatalog if you need to filter the browser dialog to another type. For example you could use 'GxFilterMaps' to target .mxd documents or 'GxFilterFileGeodatabases' to specify FGDBs. You can be even more specific, for example to only choose feature classes within file geodatabases if that's what you need to do.






share|improve this answer






























    1














    Below is the code you require:



    Public Sub OpenDataset()
    ' Open a dialog for user to select FeatureClasses
    Dim pEnumGXObject As IEnumGxObject
    Set pEnumGXObject = Nothing
    Dim pGxDialog As IGxDialog
    Dim pGXObjectFilter As IGxObjectFilter
    Set pGXObjectFilter = New GxFilterFeatureClasses
    Set pGxDialog = New GxDialog
    With pGxDialog
    .AllowMultiSelect = False
    .Title = "Select a file"
    .ButtonCaption = "Select"
    Set .ObjectFilter = pGXObjectFilter
    .DoModalOpen 0, pEnumGXObject
    End With
    pEnumGXObject.Reset
    Dim pGxobject As IGxObject
    Set pGxobject = pEnumGXObject.Next
    MsgBox pGxobject.FullName
    End Sub





    share|improve this answer























    • thanks a lot for your help, and sorry for my english. This code doesn't solve the problem - "standard pGxDialog doesn't let to open any file I want". How to set the ObjectFilter to show another file type except for shp, dxf, xls?

      – Alex
      Dec 8 '15 at 7:15






    • 1





      @Alex for that it's necessary to declare your file extention in ArcCatalog because this is an object of ArcObjects Library Reference (Catalog)

      – GeoStoneMarten
      Dec 14 '15 at 13:14


















    0














    I know the question was specifically for VBA, and is a little dated, but since I found this question in a search for a solution to my similar situation, using c#.net, I will post the solution I found.



    Firstly, to open any extension not already provided by Catalog, you must define your own custom GX filter class. Below, I create a filter for XML extensions.



    public class GxCustomFilter : ESRI.ArcGIS.Catalog.IGxObjectFilter 
    private IGxObjectFilter _basicFilter;

    public GxCustomFilter()
    _basicFilter = new GxFilterBasicTypesClass();

    public bool CanChooseObject(ESRI.ArcGIS.Catalog.IGxObject obj, ref ESRI.ArcGIS.Catalog.esriDoubleClickResult result)
    //Set whether the selected object can be chosen
    bool bCanChoose = false;
    bCanChoose = false;
    if (obj is IGxFile)
    string sExt = null;
    sExt = GetExtension(obj.Name);
    if (sExt.ToLower() == ".xml") // define your extension here
    bCanChoose = true;

    return bCanChoose;

    public bool CanDisplayObject(ESRI.ArcGIS.Catalog.IGxObject obj)
    //Check if objects can be displayed
    try
    //Check objects can be displayed
    if (_basicFilter.CanDisplayObject(obj))
    return true;
    else if (obj is IGxFile)
    string sExt = null;
    sExt = GetExtension(obj.Name);
    if (sExt.ToLower() == ".xml") // define your extension here
    return true;


    catch (Exception ex)
    System.Windows.Forms.MessageBox.Show(ex.ToString());

    return false;

    public bool CanSaveObject(ESRI.ArcGIS.Catalog.IGxObject Location, string newObjectName, ref bool objectAlreadyExists)
    return false;

    public string Description
    get
    //Set filet description
    return "eXtensible Markup Language (.xml)";


    public string Name
    get
    //Set filter name
    return "XML filter";


    private string GetExtension(string sFileName)
    string tempGetExtension = null;
    //Get extension
    long pExtPos = 0;
    pExtPos = (sFileName.LastIndexOf(".") + 1);
    if (pExtPos > 0)
    tempGetExtension = sFileName.Substring((Int32)pExtPos - 1);
    else
    tempGetExtension = "";
    return tempGetExtension;




    Then, in your GxDialog, you use the custom class to define a ObjectFilter. You also have to define file filters on the GxDialog.InternalCatalog.



    IGxDialog gxDialog = new GxDialog();
    IGxCatalog gxCat = gxDialog.InternalCatalog;
    IGxFileFilter fileFilter = gxCat.FileFilter;
    if (fileFilter.FindFileType("XML") < 0)
    fileFilter.AddFileType("XML", "eXtensible Markup Language ", "");

    IGxObjectFilter objFilter = new GxCustomFilter();
    gxDialog.ObjectFilter = objFilter;


    If you wish to use the filter with a GxDialog.DoModalSave(), you must modify the custom filter class property CanSaveObject to return true.



    I hope this helps someone, as I spent longer than I would have liked figuring it out.






    share|improve this answer























      Your Answer








      StackExchange.ready(function()
      var channelOptions =
      tags: "".split(" "),
      id: "79"
      ;
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function()
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled)
      StackExchange.using("snippets", function()
      createEditor();
      );

      else
      createEditor();

      );

      function createEditor()
      StackExchange.prepareEditor(
      heartbeatType: 'answer',
      autoActivateHeartbeat: false,
      convertImagesToLinks: false,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: null,
      bindNavPrevention: true,
      postfix: "",
      imageUploader:
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      ,
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      );



      );













      draft saved

      draft discarded


















      StackExchange.ready(
      function ()
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f172986%2fany-extention-open-file-dialog%23new-answer', 'question_page');

      );

      Post as a guest















      Required, but never shown

























      4 Answers
      4






      active

      oldest

      votes








      4 Answers
      4






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes









      1














      You can call directly COM object dll



      Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

      Private Type OPENFILENAME
      lStructSize As Long
      hwndOwner As Long
      hInstance As Long
      lpstrFilter As String
      lpstrCustomFilter As String
      nMaxCustFilter As Long
      nFilterIndex As Long
      lpstrFile As String
      nMaxFile As Long
      lpstrFileTitle As String
      nMaxFileTitle As Long
      lpstrInitialDir As String
      lpstrTitle As String
      flags As Long
      nFileOffset As Integer
      nFileExtension As Integer
      lpstrDefExt As String
      lCustData As Long
      lpfnHook As Long
      lpTemplateName As String
      End Type

      Function f_OpenFileName(Titre As String) As String
      'Function for select file
      Dim OpenFile As OPENFILENAME
      Dim lReturn As Long
      Dim sFilter As String

      OpenFile.lStructSize = Len(OpenFile)

      'Filter
      sFilter = "prj" & Chr(0) & "*.prj" & Chr(0) & Chr(0)
      OpenFile.lpstrFilter = sFilter
      OpenFile.nFilterIndex = 1
      OpenFile.lpstrFile = String(257, 0)
      OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
      OpenFile.lpstrFileTitle = OpenFile.lpstrFile
      OpenFile.nMaxFileTitle = OpenFile.nMaxFile

      ' default path
      OpenFile.lpstrInitialDir = "c:"

      'Title
      OpenFile.lpstrTitle = Titre
      OpenFile.flags = 0
      lReturn = GetOpenFileName(OpenFile)

      If lReturn = 0 Then
      'message
      f_OpenFileName = 0
      Else
      f_OpenFileName = Trim(OpenFile.lpstrFile)
      End If
      End Function


      use function:



      Dim txtSelectFile As String
      path = f_OpenFileName( "Select a file" )





      share|improve this answer

























      • @Alex for your information, all vba code exist in Arcgis v9. You can import dll as reference or call as previous method. In addition VBA is depreciated and will disappear. I suggest you to migrate your code to VB.NET solution or start new development with python.

        – GeoStoneMarten
        Dec 8 '15 at 10:16











      • thanks for information. I heard about VBA disappearing. I'm intending to learn how to make add-ins in VisualStudio in vb.net. I think it's a good idea and hope this way of arcGIS developing won't disappear too.

        – Alex
        Dec 8 '15 at 12:00















      1














      You can call directly COM object dll



      Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

      Private Type OPENFILENAME
      lStructSize As Long
      hwndOwner As Long
      hInstance As Long
      lpstrFilter As String
      lpstrCustomFilter As String
      nMaxCustFilter As Long
      nFilterIndex As Long
      lpstrFile As String
      nMaxFile As Long
      lpstrFileTitle As String
      nMaxFileTitle As Long
      lpstrInitialDir As String
      lpstrTitle As String
      flags As Long
      nFileOffset As Integer
      nFileExtension As Integer
      lpstrDefExt As String
      lCustData As Long
      lpfnHook As Long
      lpTemplateName As String
      End Type

      Function f_OpenFileName(Titre As String) As String
      'Function for select file
      Dim OpenFile As OPENFILENAME
      Dim lReturn As Long
      Dim sFilter As String

      OpenFile.lStructSize = Len(OpenFile)

      'Filter
      sFilter = "prj" & Chr(0) & "*.prj" & Chr(0) & Chr(0)
      OpenFile.lpstrFilter = sFilter
      OpenFile.nFilterIndex = 1
      OpenFile.lpstrFile = String(257, 0)
      OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
      OpenFile.lpstrFileTitle = OpenFile.lpstrFile
      OpenFile.nMaxFileTitle = OpenFile.nMaxFile

      ' default path
      OpenFile.lpstrInitialDir = "c:"

      'Title
      OpenFile.lpstrTitle = Titre
      OpenFile.flags = 0
      lReturn = GetOpenFileName(OpenFile)

      If lReturn = 0 Then
      'message
      f_OpenFileName = 0
      Else
      f_OpenFileName = Trim(OpenFile.lpstrFile)
      End If
      End Function


      use function:



      Dim txtSelectFile As String
      path = f_OpenFileName( "Select a file" )





      share|improve this answer

























      • @Alex for your information, all vba code exist in Arcgis v9. You can import dll as reference or call as previous method. In addition VBA is depreciated and will disappear. I suggest you to migrate your code to VB.NET solution or start new development with python.

        – GeoStoneMarten
        Dec 8 '15 at 10:16











      • thanks for information. I heard about VBA disappearing. I'm intending to learn how to make add-ins in VisualStudio in vb.net. I think it's a good idea and hope this way of arcGIS developing won't disappear too.

        – Alex
        Dec 8 '15 at 12:00













      1












      1








      1







      You can call directly COM object dll



      Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

      Private Type OPENFILENAME
      lStructSize As Long
      hwndOwner As Long
      hInstance As Long
      lpstrFilter As String
      lpstrCustomFilter As String
      nMaxCustFilter As Long
      nFilterIndex As Long
      lpstrFile As String
      nMaxFile As Long
      lpstrFileTitle As String
      nMaxFileTitle As Long
      lpstrInitialDir As String
      lpstrTitle As String
      flags As Long
      nFileOffset As Integer
      nFileExtension As Integer
      lpstrDefExt As String
      lCustData As Long
      lpfnHook As Long
      lpTemplateName As String
      End Type

      Function f_OpenFileName(Titre As String) As String
      'Function for select file
      Dim OpenFile As OPENFILENAME
      Dim lReturn As Long
      Dim sFilter As String

      OpenFile.lStructSize = Len(OpenFile)

      'Filter
      sFilter = "prj" & Chr(0) & "*.prj" & Chr(0) & Chr(0)
      OpenFile.lpstrFilter = sFilter
      OpenFile.nFilterIndex = 1
      OpenFile.lpstrFile = String(257, 0)
      OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
      OpenFile.lpstrFileTitle = OpenFile.lpstrFile
      OpenFile.nMaxFileTitle = OpenFile.nMaxFile

      ' default path
      OpenFile.lpstrInitialDir = "c:"

      'Title
      OpenFile.lpstrTitle = Titre
      OpenFile.flags = 0
      lReturn = GetOpenFileName(OpenFile)

      If lReturn = 0 Then
      'message
      f_OpenFileName = 0
      Else
      f_OpenFileName = Trim(OpenFile.lpstrFile)
      End If
      End Function


      use function:



      Dim txtSelectFile As String
      path = f_OpenFileName( "Select a file" )





      share|improve this answer















      You can call directly COM object dll



      Private Declare Function GetOpenFileName Lib "comdlg32.dll" Alias "GetOpenFileNameA" (pOpenfilename As OPENFILENAME) As Long

      Private Type OPENFILENAME
      lStructSize As Long
      hwndOwner As Long
      hInstance As Long
      lpstrFilter As String
      lpstrCustomFilter As String
      nMaxCustFilter As Long
      nFilterIndex As Long
      lpstrFile As String
      nMaxFile As Long
      lpstrFileTitle As String
      nMaxFileTitle As Long
      lpstrInitialDir As String
      lpstrTitle As String
      flags As Long
      nFileOffset As Integer
      nFileExtension As Integer
      lpstrDefExt As String
      lCustData As Long
      lpfnHook As Long
      lpTemplateName As String
      End Type

      Function f_OpenFileName(Titre As String) As String
      'Function for select file
      Dim OpenFile As OPENFILENAME
      Dim lReturn As Long
      Dim sFilter As String

      OpenFile.lStructSize = Len(OpenFile)

      'Filter
      sFilter = "prj" & Chr(0) & "*.prj" & Chr(0) & Chr(0)
      OpenFile.lpstrFilter = sFilter
      OpenFile.nFilterIndex = 1
      OpenFile.lpstrFile = String(257, 0)
      OpenFile.nMaxFile = Len(OpenFile.lpstrFile) - 1
      OpenFile.lpstrFileTitle = OpenFile.lpstrFile
      OpenFile.nMaxFileTitle = OpenFile.nMaxFile

      ' default path
      OpenFile.lpstrInitialDir = "c:"

      'Title
      OpenFile.lpstrTitle = Titre
      OpenFile.flags = 0
      lReturn = GetOpenFileName(OpenFile)

      If lReturn = 0 Then
      'message
      f_OpenFileName = 0
      Else
      f_OpenFileName = Trim(OpenFile.lpstrFile)
      End If
      End Function


      use function:



      Dim txtSelectFile As String
      path = f_OpenFileName( "Select a file" )






      share|improve this answer














      share|improve this answer



      share|improve this answer








      edited Dec 8 '15 at 10:07









      Alex

      999




      999










      answered Dec 7 '15 at 21:23









      GeoStoneMartenGeoStoneMarten

      1,1021025




      1,1021025












      • @Alex for your information, all vba code exist in Arcgis v9. You can import dll as reference or call as previous method. In addition VBA is depreciated and will disappear. I suggest you to migrate your code to VB.NET solution or start new development with python.

        – GeoStoneMarten
        Dec 8 '15 at 10:16











      • thanks for information. I heard about VBA disappearing. I'm intending to learn how to make add-ins in VisualStudio in vb.net. I think it's a good idea and hope this way of arcGIS developing won't disappear too.

        – Alex
        Dec 8 '15 at 12:00

















      • @Alex for your information, all vba code exist in Arcgis v9. You can import dll as reference or call as previous method. In addition VBA is depreciated and will disappear. I suggest you to migrate your code to VB.NET solution or start new development with python.

        – GeoStoneMarten
        Dec 8 '15 at 10:16











      • thanks for information. I heard about VBA disappearing. I'm intending to learn how to make add-ins in VisualStudio in vb.net. I think it's a good idea and hope this way of arcGIS developing won't disappear too.

        – Alex
        Dec 8 '15 at 12:00
















      @Alex for your information, all vba code exist in Arcgis v9. You can import dll as reference or call as previous method. In addition VBA is depreciated and will disappear. I suggest you to migrate your code to VB.NET solution or start new development with python.

      – GeoStoneMarten
      Dec 8 '15 at 10:16





      @Alex for your information, all vba code exist in Arcgis v9. You can import dll as reference or call as previous method. In addition VBA is depreciated and will disappear. I suggest you to migrate your code to VB.NET solution or start new development with python.

      – GeoStoneMarten
      Dec 8 '15 at 10:16













      thanks for information. I heard about VBA disappearing. I'm intending to learn how to make add-ins in VisualStudio in vb.net. I think it's a good idea and hope this way of arcGIS developing won't disappear too.

      – Alex
      Dec 8 '15 at 12:00





      thanks for information. I heard about VBA disappearing. I'm intending to learn how to make add-ins in VisualStudio in vb.net. I think it's a good idea and hope this way of arcGIS developing won't disappear too.

      – Alex
      Dec 8 '15 at 12:00













      2














      This is substantially the work of Radar in an answer to a similar question, using the same ArcObjects as Hornbydd does.



      I have modified Radar's function for my clients to select a delimited text file then this function returns both the path to the selected file and the file name. This fulfills Alex's request for "...return the PATH of the document to a variable"



      I trimmed it down a little so it uses just core ArcObjects libraries.



      Public Function BrowseForTextFile(ByVal sTitle As String, ByRef sFolder As String, ByRef sName As String) As Boolean
      'Source: Radar https://gis.stackexchange.com/questions/9000/opening-geodatabase-files-using-browse-dialog-command-vb-net-c-of-arcobjects
      Dim pGxDialog As IGxDialog = New GxDialog
      Dim pGxObjectFilter As IGxObjectFilter = New ESRI.ArcGIS.Catalog.GxFilterTextFiles()

      Dim pFilterCol As IGxObjectFilterCollection
      Dim pEnumGx As IEnumGxObject
      Dim pGxObject As IGxObject

      sFolder = ""
      sName = ""

      pFilterCol = pGxDialog
      pFilterCol.AddFilter(pGxObjectFilter, True)
      pGxDialog.RememberLocation = True
      pGxDialog.AllowMultiSelect = False
      pGxDialog.Title = sTitle


      If pGxDialog.DoModalOpen(0, pEnumGx) Then
      pGxObject = pEnumGx.Next
      sName = pGxObject.Name
      sFolder = pGxObject.Parent.FullName

      Return True
      End If

      End Function


      You can call this with



      Imports ESRI.ArcGIS.Catalog 'for IGxObjectFilter
      Imports ESRI.ArcGIS.CatalogUI 'for IGXdialog

      Friend m_sFilePathName As String
      '...snipped
      Dim sCSVPath As String
      Dim sCSVName As String
      If BrowseForTextFile("Choose a text file to load", sCSVPath, sCSVName) Then
      m_sFilePathName = sCSVPath & "" & sCSVName
      MsgBox("The file you chose was " & m_sFilePathName,MsgBoxStyle.Information, "Result")
      Else
      'Nothing chosen, Abort
      Exit Sub
      End If


      In this case I all I want shown in the dialog is delimited text files, so I use 'GxObjectFilter' of 'GxFilterTextFiles'. You could specify 'GxFilterFiles' if you just want to be able to select "any file"



      There are also scores upon scores of coclasses and classes for every object in ArcCatalog if you need to filter the browser dialog to another type. For example you could use 'GxFilterMaps' to target .mxd documents or 'GxFilterFileGeodatabases' to specify FGDBs. You can be even more specific, for example to only choose feature classes within file geodatabases if that's what you need to do.






      share|improve this answer



























        2














        This is substantially the work of Radar in an answer to a similar question, using the same ArcObjects as Hornbydd does.



        I have modified Radar's function for my clients to select a delimited text file then this function returns both the path to the selected file and the file name. This fulfills Alex's request for "...return the PATH of the document to a variable"



        I trimmed it down a little so it uses just core ArcObjects libraries.



        Public Function BrowseForTextFile(ByVal sTitle As String, ByRef sFolder As String, ByRef sName As String) As Boolean
        'Source: Radar https://gis.stackexchange.com/questions/9000/opening-geodatabase-files-using-browse-dialog-command-vb-net-c-of-arcobjects
        Dim pGxDialog As IGxDialog = New GxDialog
        Dim pGxObjectFilter As IGxObjectFilter = New ESRI.ArcGIS.Catalog.GxFilterTextFiles()

        Dim pFilterCol As IGxObjectFilterCollection
        Dim pEnumGx As IEnumGxObject
        Dim pGxObject As IGxObject

        sFolder = ""
        sName = ""

        pFilterCol = pGxDialog
        pFilterCol.AddFilter(pGxObjectFilter, True)
        pGxDialog.RememberLocation = True
        pGxDialog.AllowMultiSelect = False
        pGxDialog.Title = sTitle


        If pGxDialog.DoModalOpen(0, pEnumGx) Then
        pGxObject = pEnumGx.Next
        sName = pGxObject.Name
        sFolder = pGxObject.Parent.FullName

        Return True
        End If

        End Function


        You can call this with



        Imports ESRI.ArcGIS.Catalog 'for IGxObjectFilter
        Imports ESRI.ArcGIS.CatalogUI 'for IGXdialog

        Friend m_sFilePathName As String
        '...snipped
        Dim sCSVPath As String
        Dim sCSVName As String
        If BrowseForTextFile("Choose a text file to load", sCSVPath, sCSVName) Then
        m_sFilePathName = sCSVPath & "" & sCSVName
        MsgBox("The file you chose was " & m_sFilePathName,MsgBoxStyle.Information, "Result")
        Else
        'Nothing chosen, Abort
        Exit Sub
        End If


        In this case I all I want shown in the dialog is delimited text files, so I use 'GxObjectFilter' of 'GxFilterTextFiles'. You could specify 'GxFilterFiles' if you just want to be able to select "any file"



        There are also scores upon scores of coclasses and classes for every object in ArcCatalog if you need to filter the browser dialog to another type. For example you could use 'GxFilterMaps' to target .mxd documents or 'GxFilterFileGeodatabases' to specify FGDBs. You can be even more specific, for example to only choose feature classes within file geodatabases if that's what you need to do.






        share|improve this answer

























          2












          2








          2







          This is substantially the work of Radar in an answer to a similar question, using the same ArcObjects as Hornbydd does.



          I have modified Radar's function for my clients to select a delimited text file then this function returns both the path to the selected file and the file name. This fulfills Alex's request for "...return the PATH of the document to a variable"



          I trimmed it down a little so it uses just core ArcObjects libraries.



          Public Function BrowseForTextFile(ByVal sTitle As String, ByRef sFolder As String, ByRef sName As String) As Boolean
          'Source: Radar https://gis.stackexchange.com/questions/9000/opening-geodatabase-files-using-browse-dialog-command-vb-net-c-of-arcobjects
          Dim pGxDialog As IGxDialog = New GxDialog
          Dim pGxObjectFilter As IGxObjectFilter = New ESRI.ArcGIS.Catalog.GxFilterTextFiles()

          Dim pFilterCol As IGxObjectFilterCollection
          Dim pEnumGx As IEnumGxObject
          Dim pGxObject As IGxObject

          sFolder = ""
          sName = ""

          pFilterCol = pGxDialog
          pFilterCol.AddFilter(pGxObjectFilter, True)
          pGxDialog.RememberLocation = True
          pGxDialog.AllowMultiSelect = False
          pGxDialog.Title = sTitle


          If pGxDialog.DoModalOpen(0, pEnumGx) Then
          pGxObject = pEnumGx.Next
          sName = pGxObject.Name
          sFolder = pGxObject.Parent.FullName

          Return True
          End If

          End Function


          You can call this with



          Imports ESRI.ArcGIS.Catalog 'for IGxObjectFilter
          Imports ESRI.ArcGIS.CatalogUI 'for IGXdialog

          Friend m_sFilePathName As String
          '...snipped
          Dim sCSVPath As String
          Dim sCSVName As String
          If BrowseForTextFile("Choose a text file to load", sCSVPath, sCSVName) Then
          m_sFilePathName = sCSVPath & "" & sCSVName
          MsgBox("The file you chose was " & m_sFilePathName,MsgBoxStyle.Information, "Result")
          Else
          'Nothing chosen, Abort
          Exit Sub
          End If


          In this case I all I want shown in the dialog is delimited text files, so I use 'GxObjectFilter' of 'GxFilterTextFiles'. You could specify 'GxFilterFiles' if you just want to be able to select "any file"



          There are also scores upon scores of coclasses and classes for every object in ArcCatalog if you need to filter the browser dialog to another type. For example you could use 'GxFilterMaps' to target .mxd documents or 'GxFilterFileGeodatabases' to specify FGDBs. You can be even more specific, for example to only choose feature classes within file geodatabases if that's what you need to do.






          share|improve this answer













          This is substantially the work of Radar in an answer to a similar question, using the same ArcObjects as Hornbydd does.



          I have modified Radar's function for my clients to select a delimited text file then this function returns both the path to the selected file and the file name. This fulfills Alex's request for "...return the PATH of the document to a variable"



          I trimmed it down a little so it uses just core ArcObjects libraries.



          Public Function BrowseForTextFile(ByVal sTitle As String, ByRef sFolder As String, ByRef sName As String) As Boolean
          'Source: Radar https://gis.stackexchange.com/questions/9000/opening-geodatabase-files-using-browse-dialog-command-vb-net-c-of-arcobjects
          Dim pGxDialog As IGxDialog = New GxDialog
          Dim pGxObjectFilter As IGxObjectFilter = New ESRI.ArcGIS.Catalog.GxFilterTextFiles()

          Dim pFilterCol As IGxObjectFilterCollection
          Dim pEnumGx As IEnumGxObject
          Dim pGxObject As IGxObject

          sFolder = ""
          sName = ""

          pFilterCol = pGxDialog
          pFilterCol.AddFilter(pGxObjectFilter, True)
          pGxDialog.RememberLocation = True
          pGxDialog.AllowMultiSelect = False
          pGxDialog.Title = sTitle


          If pGxDialog.DoModalOpen(0, pEnumGx) Then
          pGxObject = pEnumGx.Next
          sName = pGxObject.Name
          sFolder = pGxObject.Parent.FullName

          Return True
          End If

          End Function


          You can call this with



          Imports ESRI.ArcGIS.Catalog 'for IGxObjectFilter
          Imports ESRI.ArcGIS.CatalogUI 'for IGXdialog

          Friend m_sFilePathName As String
          '...snipped
          Dim sCSVPath As String
          Dim sCSVName As String
          If BrowseForTextFile("Choose a text file to load", sCSVPath, sCSVName) Then
          m_sFilePathName = sCSVPath & "" & sCSVName
          MsgBox("The file you chose was " & m_sFilePathName,MsgBoxStyle.Information, "Result")
          Else
          'Nothing chosen, Abort
          Exit Sub
          End If


          In this case I all I want shown in the dialog is delimited text files, so I use 'GxObjectFilter' of 'GxFilterTextFiles'. You could specify 'GxFilterFiles' if you just want to be able to select "any file"



          There are also scores upon scores of coclasses and classes for every object in ArcCatalog if you need to filter the browser dialog to another type. For example you could use 'GxFilterMaps' to target .mxd documents or 'GxFilterFileGeodatabases' to specify FGDBs. You can be even more specific, for example to only choose feature classes within file geodatabases if that's what you need to do.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 10 '17 at 3:35









          drewdqueuedrewdqueue

          213




          213





















              1














              Below is the code you require:



              Public Sub OpenDataset()
              ' Open a dialog for user to select FeatureClasses
              Dim pEnumGXObject As IEnumGxObject
              Set pEnumGXObject = Nothing
              Dim pGxDialog As IGxDialog
              Dim pGXObjectFilter As IGxObjectFilter
              Set pGXObjectFilter = New GxFilterFeatureClasses
              Set pGxDialog = New GxDialog
              With pGxDialog
              .AllowMultiSelect = False
              .Title = "Select a file"
              .ButtonCaption = "Select"
              Set .ObjectFilter = pGXObjectFilter
              .DoModalOpen 0, pEnumGXObject
              End With
              pEnumGXObject.Reset
              Dim pGxobject As IGxObject
              Set pGxobject = pEnumGXObject.Next
              MsgBox pGxobject.FullName
              End Sub





              share|improve this answer























              • thanks a lot for your help, and sorry for my english. This code doesn't solve the problem - "standard pGxDialog doesn't let to open any file I want". How to set the ObjectFilter to show another file type except for shp, dxf, xls?

                – Alex
                Dec 8 '15 at 7:15






              • 1





                @Alex for that it's necessary to declare your file extention in ArcCatalog because this is an object of ArcObjects Library Reference (Catalog)

                – GeoStoneMarten
                Dec 14 '15 at 13:14















              1














              Below is the code you require:



              Public Sub OpenDataset()
              ' Open a dialog for user to select FeatureClasses
              Dim pEnumGXObject As IEnumGxObject
              Set pEnumGXObject = Nothing
              Dim pGxDialog As IGxDialog
              Dim pGXObjectFilter As IGxObjectFilter
              Set pGXObjectFilter = New GxFilterFeatureClasses
              Set pGxDialog = New GxDialog
              With pGxDialog
              .AllowMultiSelect = False
              .Title = "Select a file"
              .ButtonCaption = "Select"
              Set .ObjectFilter = pGXObjectFilter
              .DoModalOpen 0, pEnumGXObject
              End With
              pEnumGXObject.Reset
              Dim pGxobject As IGxObject
              Set pGxobject = pEnumGXObject.Next
              MsgBox pGxobject.FullName
              End Sub





              share|improve this answer























              • thanks a lot for your help, and sorry for my english. This code doesn't solve the problem - "standard pGxDialog doesn't let to open any file I want". How to set the ObjectFilter to show another file type except for shp, dxf, xls?

                – Alex
                Dec 8 '15 at 7:15






              • 1





                @Alex for that it's necessary to declare your file extention in ArcCatalog because this is an object of ArcObjects Library Reference (Catalog)

                – GeoStoneMarten
                Dec 14 '15 at 13:14













              1












              1








              1







              Below is the code you require:



              Public Sub OpenDataset()
              ' Open a dialog for user to select FeatureClasses
              Dim pEnumGXObject As IEnumGxObject
              Set pEnumGXObject = Nothing
              Dim pGxDialog As IGxDialog
              Dim pGXObjectFilter As IGxObjectFilter
              Set pGXObjectFilter = New GxFilterFeatureClasses
              Set pGxDialog = New GxDialog
              With pGxDialog
              .AllowMultiSelect = False
              .Title = "Select a file"
              .ButtonCaption = "Select"
              Set .ObjectFilter = pGXObjectFilter
              .DoModalOpen 0, pEnumGXObject
              End With
              pEnumGXObject.Reset
              Dim pGxobject As IGxObject
              Set pGxobject = pEnumGXObject.Next
              MsgBox pGxobject.FullName
              End Sub





              share|improve this answer













              Below is the code you require:



              Public Sub OpenDataset()
              ' Open a dialog for user to select FeatureClasses
              Dim pEnumGXObject As IEnumGxObject
              Set pEnumGXObject = Nothing
              Dim pGxDialog As IGxDialog
              Dim pGXObjectFilter As IGxObjectFilter
              Set pGXObjectFilter = New GxFilterFeatureClasses
              Set pGxDialog = New GxDialog
              With pGxDialog
              .AllowMultiSelect = False
              .Title = "Select a file"
              .ButtonCaption = "Select"
              Set .ObjectFilter = pGXObjectFilter
              .DoModalOpen 0, pEnumGXObject
              End With
              pEnumGXObject.Reset
              Dim pGxobject As IGxObject
              Set pGxobject = pEnumGXObject.Next
              MsgBox pGxobject.FullName
              End Sub






              share|improve this answer












              share|improve this answer



              share|improve this answer










              answered Dec 7 '15 at 20:54









              HornbyddHornbydd

              27k32957




              27k32957












              • thanks a lot for your help, and sorry for my english. This code doesn't solve the problem - "standard pGxDialog doesn't let to open any file I want". How to set the ObjectFilter to show another file type except for shp, dxf, xls?

                – Alex
                Dec 8 '15 at 7:15






              • 1





                @Alex for that it's necessary to declare your file extention in ArcCatalog because this is an object of ArcObjects Library Reference (Catalog)

                – GeoStoneMarten
                Dec 14 '15 at 13:14

















              • thanks a lot for your help, and sorry for my english. This code doesn't solve the problem - "standard pGxDialog doesn't let to open any file I want". How to set the ObjectFilter to show another file type except for shp, dxf, xls?

                – Alex
                Dec 8 '15 at 7:15






              • 1





                @Alex for that it's necessary to declare your file extention in ArcCatalog because this is an object of ArcObjects Library Reference (Catalog)

                – GeoStoneMarten
                Dec 14 '15 at 13:14
















              thanks a lot for your help, and sorry for my english. This code doesn't solve the problem - "standard pGxDialog doesn't let to open any file I want". How to set the ObjectFilter to show another file type except for shp, dxf, xls?

              – Alex
              Dec 8 '15 at 7:15





              thanks a lot for your help, and sorry for my english. This code doesn't solve the problem - "standard pGxDialog doesn't let to open any file I want". How to set the ObjectFilter to show another file type except for shp, dxf, xls?

              – Alex
              Dec 8 '15 at 7:15




              1




              1





              @Alex for that it's necessary to declare your file extention in ArcCatalog because this is an object of ArcObjects Library Reference (Catalog)

              – GeoStoneMarten
              Dec 14 '15 at 13:14





              @Alex for that it's necessary to declare your file extention in ArcCatalog because this is an object of ArcObjects Library Reference (Catalog)

              – GeoStoneMarten
              Dec 14 '15 at 13:14











              0














              I know the question was specifically for VBA, and is a little dated, but since I found this question in a search for a solution to my similar situation, using c#.net, I will post the solution I found.



              Firstly, to open any extension not already provided by Catalog, you must define your own custom GX filter class. Below, I create a filter for XML extensions.



              public class GxCustomFilter : ESRI.ArcGIS.Catalog.IGxObjectFilter 
              private IGxObjectFilter _basicFilter;

              public GxCustomFilter()
              _basicFilter = new GxFilterBasicTypesClass();

              public bool CanChooseObject(ESRI.ArcGIS.Catalog.IGxObject obj, ref ESRI.ArcGIS.Catalog.esriDoubleClickResult result)
              //Set whether the selected object can be chosen
              bool bCanChoose = false;
              bCanChoose = false;
              if (obj is IGxFile)
              string sExt = null;
              sExt = GetExtension(obj.Name);
              if (sExt.ToLower() == ".xml") // define your extension here
              bCanChoose = true;

              return bCanChoose;

              public bool CanDisplayObject(ESRI.ArcGIS.Catalog.IGxObject obj)
              //Check if objects can be displayed
              try
              //Check objects can be displayed
              if (_basicFilter.CanDisplayObject(obj))
              return true;
              else if (obj is IGxFile)
              string sExt = null;
              sExt = GetExtension(obj.Name);
              if (sExt.ToLower() == ".xml") // define your extension here
              return true;


              catch (Exception ex)
              System.Windows.Forms.MessageBox.Show(ex.ToString());

              return false;

              public bool CanSaveObject(ESRI.ArcGIS.Catalog.IGxObject Location, string newObjectName, ref bool objectAlreadyExists)
              return false;

              public string Description
              get
              //Set filet description
              return "eXtensible Markup Language (.xml)";


              public string Name
              get
              //Set filter name
              return "XML filter";


              private string GetExtension(string sFileName)
              string tempGetExtension = null;
              //Get extension
              long pExtPos = 0;
              pExtPos = (sFileName.LastIndexOf(".") + 1);
              if (pExtPos > 0)
              tempGetExtension = sFileName.Substring((Int32)pExtPos - 1);
              else
              tempGetExtension = "";
              return tempGetExtension;




              Then, in your GxDialog, you use the custom class to define a ObjectFilter. You also have to define file filters on the GxDialog.InternalCatalog.



              IGxDialog gxDialog = new GxDialog();
              IGxCatalog gxCat = gxDialog.InternalCatalog;
              IGxFileFilter fileFilter = gxCat.FileFilter;
              if (fileFilter.FindFileType("XML") < 0)
              fileFilter.AddFileType("XML", "eXtensible Markup Language ", "");

              IGxObjectFilter objFilter = new GxCustomFilter();
              gxDialog.ObjectFilter = objFilter;


              If you wish to use the filter with a GxDialog.DoModalSave(), you must modify the custom filter class property CanSaveObject to return true.



              I hope this helps someone, as I spent longer than I would have liked figuring it out.






              share|improve this answer



























                0














                I know the question was specifically for VBA, and is a little dated, but since I found this question in a search for a solution to my similar situation, using c#.net, I will post the solution I found.



                Firstly, to open any extension not already provided by Catalog, you must define your own custom GX filter class. Below, I create a filter for XML extensions.



                public class GxCustomFilter : ESRI.ArcGIS.Catalog.IGxObjectFilter 
                private IGxObjectFilter _basicFilter;

                public GxCustomFilter()
                _basicFilter = new GxFilterBasicTypesClass();

                public bool CanChooseObject(ESRI.ArcGIS.Catalog.IGxObject obj, ref ESRI.ArcGIS.Catalog.esriDoubleClickResult result)
                //Set whether the selected object can be chosen
                bool bCanChoose = false;
                bCanChoose = false;
                if (obj is IGxFile)
                string sExt = null;
                sExt = GetExtension(obj.Name);
                if (sExt.ToLower() == ".xml") // define your extension here
                bCanChoose = true;

                return bCanChoose;

                public bool CanDisplayObject(ESRI.ArcGIS.Catalog.IGxObject obj)
                //Check if objects can be displayed
                try
                //Check objects can be displayed
                if (_basicFilter.CanDisplayObject(obj))
                return true;
                else if (obj is IGxFile)
                string sExt = null;
                sExt = GetExtension(obj.Name);
                if (sExt.ToLower() == ".xml") // define your extension here
                return true;


                catch (Exception ex)
                System.Windows.Forms.MessageBox.Show(ex.ToString());

                return false;

                public bool CanSaveObject(ESRI.ArcGIS.Catalog.IGxObject Location, string newObjectName, ref bool objectAlreadyExists)
                return false;

                public string Description
                get
                //Set filet description
                return "eXtensible Markup Language (.xml)";


                public string Name
                get
                //Set filter name
                return "XML filter";


                private string GetExtension(string sFileName)
                string tempGetExtension = null;
                //Get extension
                long pExtPos = 0;
                pExtPos = (sFileName.LastIndexOf(".") + 1);
                if (pExtPos > 0)
                tempGetExtension = sFileName.Substring((Int32)pExtPos - 1);
                else
                tempGetExtension = "";
                return tempGetExtension;




                Then, in your GxDialog, you use the custom class to define a ObjectFilter. You also have to define file filters on the GxDialog.InternalCatalog.



                IGxDialog gxDialog = new GxDialog();
                IGxCatalog gxCat = gxDialog.InternalCatalog;
                IGxFileFilter fileFilter = gxCat.FileFilter;
                if (fileFilter.FindFileType("XML") < 0)
                fileFilter.AddFileType("XML", "eXtensible Markup Language ", "");

                IGxObjectFilter objFilter = new GxCustomFilter();
                gxDialog.ObjectFilter = objFilter;


                If you wish to use the filter with a GxDialog.DoModalSave(), you must modify the custom filter class property CanSaveObject to return true.



                I hope this helps someone, as I spent longer than I would have liked figuring it out.






                share|improve this answer

























                  0












                  0








                  0







                  I know the question was specifically for VBA, and is a little dated, but since I found this question in a search for a solution to my similar situation, using c#.net, I will post the solution I found.



                  Firstly, to open any extension not already provided by Catalog, you must define your own custom GX filter class. Below, I create a filter for XML extensions.



                  public class GxCustomFilter : ESRI.ArcGIS.Catalog.IGxObjectFilter 
                  private IGxObjectFilter _basicFilter;

                  public GxCustomFilter()
                  _basicFilter = new GxFilterBasicTypesClass();

                  public bool CanChooseObject(ESRI.ArcGIS.Catalog.IGxObject obj, ref ESRI.ArcGIS.Catalog.esriDoubleClickResult result)
                  //Set whether the selected object can be chosen
                  bool bCanChoose = false;
                  bCanChoose = false;
                  if (obj is IGxFile)
                  string sExt = null;
                  sExt = GetExtension(obj.Name);
                  if (sExt.ToLower() == ".xml") // define your extension here
                  bCanChoose = true;

                  return bCanChoose;

                  public bool CanDisplayObject(ESRI.ArcGIS.Catalog.IGxObject obj)
                  //Check if objects can be displayed
                  try
                  //Check objects can be displayed
                  if (_basicFilter.CanDisplayObject(obj))
                  return true;
                  else if (obj is IGxFile)
                  string sExt = null;
                  sExt = GetExtension(obj.Name);
                  if (sExt.ToLower() == ".xml") // define your extension here
                  return true;


                  catch (Exception ex)
                  System.Windows.Forms.MessageBox.Show(ex.ToString());

                  return false;

                  public bool CanSaveObject(ESRI.ArcGIS.Catalog.IGxObject Location, string newObjectName, ref bool objectAlreadyExists)
                  return false;

                  public string Description
                  get
                  //Set filet description
                  return "eXtensible Markup Language (.xml)";


                  public string Name
                  get
                  //Set filter name
                  return "XML filter";


                  private string GetExtension(string sFileName)
                  string tempGetExtension = null;
                  //Get extension
                  long pExtPos = 0;
                  pExtPos = (sFileName.LastIndexOf(".") + 1);
                  if (pExtPos > 0)
                  tempGetExtension = sFileName.Substring((Int32)pExtPos - 1);
                  else
                  tempGetExtension = "";
                  return tempGetExtension;




                  Then, in your GxDialog, you use the custom class to define a ObjectFilter. You also have to define file filters on the GxDialog.InternalCatalog.



                  IGxDialog gxDialog = new GxDialog();
                  IGxCatalog gxCat = gxDialog.InternalCatalog;
                  IGxFileFilter fileFilter = gxCat.FileFilter;
                  if (fileFilter.FindFileType("XML") < 0)
                  fileFilter.AddFileType("XML", "eXtensible Markup Language ", "");

                  IGxObjectFilter objFilter = new GxCustomFilter();
                  gxDialog.ObjectFilter = objFilter;


                  If you wish to use the filter with a GxDialog.DoModalSave(), you must modify the custom filter class property CanSaveObject to return true.



                  I hope this helps someone, as I spent longer than I would have liked figuring it out.






                  share|improve this answer













                  I know the question was specifically for VBA, and is a little dated, but since I found this question in a search for a solution to my similar situation, using c#.net, I will post the solution I found.



                  Firstly, to open any extension not already provided by Catalog, you must define your own custom GX filter class. Below, I create a filter for XML extensions.



                  public class GxCustomFilter : ESRI.ArcGIS.Catalog.IGxObjectFilter 
                  private IGxObjectFilter _basicFilter;

                  public GxCustomFilter()
                  _basicFilter = new GxFilterBasicTypesClass();

                  public bool CanChooseObject(ESRI.ArcGIS.Catalog.IGxObject obj, ref ESRI.ArcGIS.Catalog.esriDoubleClickResult result)
                  //Set whether the selected object can be chosen
                  bool bCanChoose = false;
                  bCanChoose = false;
                  if (obj is IGxFile)
                  string sExt = null;
                  sExt = GetExtension(obj.Name);
                  if (sExt.ToLower() == ".xml") // define your extension here
                  bCanChoose = true;

                  return bCanChoose;

                  public bool CanDisplayObject(ESRI.ArcGIS.Catalog.IGxObject obj)
                  //Check if objects can be displayed
                  try
                  //Check objects can be displayed
                  if (_basicFilter.CanDisplayObject(obj))
                  return true;
                  else if (obj is IGxFile)
                  string sExt = null;
                  sExt = GetExtension(obj.Name);
                  if (sExt.ToLower() == ".xml") // define your extension here
                  return true;


                  catch (Exception ex)
                  System.Windows.Forms.MessageBox.Show(ex.ToString());

                  return false;

                  public bool CanSaveObject(ESRI.ArcGIS.Catalog.IGxObject Location, string newObjectName, ref bool objectAlreadyExists)
                  return false;

                  public string Description
                  get
                  //Set filet description
                  return "eXtensible Markup Language (.xml)";


                  public string Name
                  get
                  //Set filter name
                  return "XML filter";


                  private string GetExtension(string sFileName)
                  string tempGetExtension = null;
                  //Get extension
                  long pExtPos = 0;
                  pExtPos = (sFileName.LastIndexOf(".") + 1);
                  if (pExtPos > 0)
                  tempGetExtension = sFileName.Substring((Int32)pExtPos - 1);
                  else
                  tempGetExtension = "";
                  return tempGetExtension;




                  Then, in your GxDialog, you use the custom class to define a ObjectFilter. You also have to define file filters on the GxDialog.InternalCatalog.



                  IGxDialog gxDialog = new GxDialog();
                  IGxCatalog gxCat = gxDialog.InternalCatalog;
                  IGxFileFilter fileFilter = gxCat.FileFilter;
                  if (fileFilter.FindFileType("XML") < 0)
                  fileFilter.AddFileType("XML", "eXtensible Markup Language ", "");

                  IGxObjectFilter objFilter = new GxCustomFilter();
                  gxDialog.ObjectFilter = objFilter;


                  If you wish to use the filter with a GxDialog.DoModalSave(), you must modify the custom filter class property CanSaveObject to return true.



                  I hope this helps someone, as I spent longer than I would have liked figuring it out.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered yesterday









                  BarbarossaBarbarossa

                  4,7241551




                  4,7241551



























                      draft saved

                      draft discarded
















































                      Thanks for contributing an answer to Geographic Information Systems Stack Exchange!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid


                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.

                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fgis.stackexchange.com%2fquestions%2f172986%2fany-extention-open-file-dialog%23new-answer', 'question_page');

                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      រឿង រ៉ូមេអូ និង ហ្ស៊ុយលីយេ សង្ខេបរឿង តួអង្គ បញ្ជីណែនាំ

                      QGIS export composer to PDF scale the map [closed] Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Announcing the arrival of Valued Associate #679: Cesar Manara Unicorn Meta Zoo #1: Why another podcast?Print Composer QGIS 2.6, how to export image?QGIS 2.8.1 print composer won't export all OpenCycleMap base layer tilesSave Print/Map QGIS composer view as PNG/PDF using Python (without changing anything in visible layout)?Export QGIS Print Composer PDF with searchable text labelsQGIS Print Composer does not change from landscape to portrait orientation?How can I avoid map size and scale changes in print composer?Fuzzy PDF export in QGIS running on macSierra OSExport the legend into its 100% size using Print ComposerScale-dependent rendering in QGIS PDF output

                      PDF-ში გადმოწერა სანავიგაციო მენიუproject page