Get the folder path of a file in Dynamics NAV without using FileManagement.OpenFolderDialog

I am trying to get the folder path of a file (e.g. "C:\folder\file.exe") in Dynamics NAV/CAL. It is trivial to do by using the standard Microsoft Codeunit 419 - File Management, as OpenFolderDialog does exactly that.

Unfortunately this uses DotNet which does not work in the Webclient (specifically System.Windows.Forms.OpenFileDialog). Any ideas how that functionality can be implemented in a way that works in the Webclient (preferably without a Javascript Addin, but if there is nothing else, I would consider that, too.)

Best Answer

Answers

  • ftorneroftornero Member Posts: 524
    If you only need to get 'C:\folder', you can use this:
    
    Path(Filename : Text[1024]) Path : Text[1024]
    Filename := DELCHR(Filename,'<');
    Path := Filename;
    WHILE STRPOS(Filename,'\')<>0 DO BEGIN
      Filename := COPYSTR(Filename, STRPOS(Filename,'\')+1);
    END;
    IF STRLEN(Path) > STRLEN(Filename) THEN
      EXIT(COPYSTR(Path,1,STRLEN(Path)-STRLEN(Filename)))
    ELSE
      EXIT('');
    
  • JuhlJuhl Member Posts: 724
    Are we talking client side or server.
    Dotnet does work server side!
    Follow me on my blog juhl.blog
  • holgerbaehrenholgerbaehren Member Posts: 4
    I probably didn't state the original question clear enough. I want the customer to select the file via an open file dialog and then write the path of the file into the database. Not a problem with OpenFolderDialog, but that does not work on the web client.
  • ftorneroftornero Member Posts: 524
    Then you can use something like that
    
    IF FileMgt.CanRunDotNetOnClient THEN
      FileName := FileMgt.OpenFileDialog('Choose file:', '','CSV files (*.csv)|*.csv|All files (*.*)|*.*')
    ELSE
      FileName := FileMgt.UploadFile('Choose file:', FileName);
    
Sign In or Register to comment.