Get a Folder (Not Reg. new DLLs)

garak
Member Posts: 3,263
When you need to browse for a folder (dialog) you can do this with using standard Windows tools :!:
Here an example:
Regards
Regards
Here an example:
Name DataType Subtype Length ShellControl Automation 'Microsoft Shell Controls And Automation'.Shell Folder Automation 'Microsoft Shell Controls And Automation'.Folder3 FolderItems Automation 'Microsoft Shell Controls And Automation'.FolderItems3 FolderItem Automation 'Microsoft Shell Controls And Automation'.FolderItem2 Foldertxt Text 1024 if isclear(ShellControl) then create(ShellControl); Folder := ShellControl.BrowseForFolder(0,'Ordner suchen',0); FolderItems := Folder.Items(); FolderItem := FolderItems.Item; Foldertxt := format(FolderItem.Path); clear(ShellControl);
Regards
Regards
Do you make it right, it works too!
0
Comments
-
Thank your for this very usefull tip!
I've immediatly added it to my "Tools Collection" ;-)Timo Lässer
Microsoft Dynamics NAV Developer since 1997
MSDynamics.de - German Microsoft Dynamics Community - member of [clip]0 -
Please. (Gern geschehen :-) )
Where can i see the "Tools Collection" :?: Maybe there is some interesting things for meDo you make it right, it works too!0 -
Be almost worth enhancing Codeunit 412 "Common Dialog Management" with this tidbit for system-wide usage. Great tip!Kristopher Webb
Microsoft Dynamics NAV Developer0 -
Thanks.Do you make it right, it works too!0
-
Hello Garak
I have tried the code given by u.But when I run the codeunit contained ur code then it is not running.It compiled fine...but run just for a moment.Can u give me the complete solution for it.0 -
Whats the problem? Let me see your source.Do you make it right, it works too!0
-
When using codeunit 412, be sure to deploy Comdlg.oca and Comdlg32.ocx along with client installations (and register it too).
Unfortunatelly this DLL may not be present in the client Windows System folder and then your application will fail.Marcelo Borges
D365 Business Central Solutions Architect
BC AL/NAV C/AL Developer
BC Repositories.com0 -
Verry nice code. Ive been trying to achieve this for some time.
In some situations however the browser window disappears to the background. A workarround for this is to provide the current window hWnd as the first parameter of the 'BrowseForFolder' function.
But i can only obtain this hWnd by writing a DLL that uses API functions to get the hWnd of the current active window. Which brings us back to the root, we didn't want to distribute extra automation objects.
Anyone got any code that obtains the hWnd of the current active window by only using excisting windows/internet explorer automation objects? :-sIn a world without Borders or Fences, who needs Windows and Gates?0 -
janpieter wrote:[...]
Anyone got any code that obtains the hWnd of the current active window by only using excisting windows/internet explorer automation objects? :-s
Yes, here it is:
ActiveWindow Automation 'CSideWindowCheck'.WindowCheck
or (if you don't have that Automation)
ActiveWindow Automation 'C/SIDE Utility Classes'.ActiveWindowIF ISCLEAR(ShellControl) THEN CREATE(ShellControl); IF ISCLEAR(ActiveWindow) THEN CREATE(ActiveWindow); EXIT(FORMAT(ShellControl.BrowseForFolder(ActiveWindow.WindowHandle,Text000,0).Items().Item.Path));
(I've optimized the code a little bit and it still works ;-) )Timo Lässer
Microsoft Dynamics NAV Developer since 1997
MSDynamics.de - German Microsoft Dynamics Community - member of [clip]0 -
hmm bunner i dont have the csidewindowcheck automation and the 'c/side utilit classes' is part of this download: http://www.mibuso.com/dlinfo.asp?FileID=169
So my conclusion is you won't be able to do this properly without adding automation.
Ehm Timo your code might look better this way but i think it will return an error if the user cancels the browse for folder window.
The most efficient working code is in my opinion:CREATE(lclsShellControl); CREATE(lclsWindowMgt); lclsFolder := lclsShellControl.BrowseForFolder(lclsWindowMgt.hwndCurrForm, lText001, 0); // if user cancels the dialog box then lclsFolder will not be set IF NOT ISCLEAR(lclsFolder) THEN BEGIN Path := lclsFolder.Items().Item.Path; CLEAR(lclsFolder); END; CLEAR(lclsWindowMgt) CLEAR(lclsShellControl);
(lclsWindowMgt is my own class you can use the one in the download above as well)In a world without Borders or Fences, who needs Windows and Gates?0 -
hey, man, this is GREAT!!!! thanks a much. for this functionality, I am looking about five years \:D/Martin Bokůvka, AxiomProvis0
-
Check the downloads for http://www.mibuso.com/dlinfo.asp?FileID=541 where you need ABSOLUTELY no automations AT ALL !
(Guess who made it?)0 -
Futher i have been experimenting with this idea but is was still bothered by the fact that the directory picker wasnt running modal. But this morning i found a sollution to this by just adding a form wrapper and run the form invisible but modal. Just create a form like this example:
global vars: Name DataType Subtype Length gtPath Text 250 gtTitle Text 250 gbSuccess Boolean Form - OnOpenForm() CurrForm.VISIBLE := FALSE; SelectDirectory(); CurrForm.CLOSE; SetParameters(Title : Text[250]) gtTitle := Title; IsSuccessFull() : Boolean EXIT(gbSuccess); GetPath() : Text[250] EXIT(gtPath); SelectDirectory() Local vars lclsShellControl Automation 'Microsoft Shell Controls And Automation'.Shell lclsFolder Automation 'Microsoft Shell Controls And Automation'.Folder3 lbSuccess Boolean Text001 TextVariable CREATE(lclsShellControl); IF (gtTitle = '') THEN BEGIN gtTitle := Text001; END; lclsFolder := lclsShellControl.BrowseForFolder(0, gtTitle, 0); gbSuccess := NOT ISCLEAR(lclsFolder); IF gbSuccess THEN BEGIN gtPath := lclsFolder.Items().Item.Path; IF (COPYSTR(gtPath, STRLEN(gtPath), 1) <> '\') THEN BEGIN gtPath := gtPath + '\'; END; CLEAR(lclsFolder); END; CLEAR(lclsShellControl);
From your application add the following code to browse for a directory:Vars: YourPathVar : Text250 lfrmSelectDirectory.SetParameters('Type a title here'); lfrmSelectDirectory.RUNMODAL(); IF lfrmSelectDirectory.IsSuccessFull THEN BEGIN YourPathVar := lfrmSelectDirectory.GetPath(); END;
[/i]In a world without Borders or Fences, who needs Windows and Gates?0 -
-
hi dudes,
if the code from GARAK doesnt suite you because of error when cancelling the window, just change it like:
IF ISCLEAR(ShellControl_Au_Loc) THEN
CREATE(ShellControl_Au_Loc);
Folder_Au_Loc := ShellControl_Au_Loc.BrowseForFolder(0,'Chose Folder',0);
:roll: IF ISCLEAR(Folder_Au_Loc) THEN
:roll: EXIT('');
FolderItems_Au_Loc := Folder_Au_Loc.Items();
FolderItem_Au_Loc := FolderItems_Au_Loc.Item;
FolderText_Te_Loc := FORMAT(FolderItem_Au_Loc.Path);
EXIT(FolderText_Te_Loc);#### Only one can survive ######0 -
@garak Big thanks Garak0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions