Select File/Folder Feature on UiPath Forum

Hi,
As all of you know that we have feature called “File/Folder Path” on Form designer, it pops out the dialog which looks like below.

Basically no one likes this Ui as its very hard to navigate to your desired folder and select it.
We prefer the below one which is more user friendly

Is there any possibility to get this feature (second one) on form in other way ? or is there any workaround to get this feature (using method or else)

Please suggest me on this.

a simple implementation will be

Dim OpenFileDlg as new OpenFileDialog
OpenFileDlg.FileName = "" ' Default file name
OpenFileDlg.DefaultExt = ".txt" ' Default file extension
OpenFileDlg.Filter = "Text Files (*.txt)|*.TXT"
OpenFileDlg.Multiselect = True
OpenFileDlg.RestoreDirectory = True
Dim result As Boolean = OpenFileDlg.ShowDialog()

I found it through this interesting link.

vb.net - Open *.txt with file selector from vb console application - Stack Overflow

thanks for reply, sorry but it didnt work and moreover its for file selection dialog not folder selection dialog

Found something even simpler Select file/Browse for file

image

image

Vote

1 Like

Hi, I have already voted, thanks a lot for raising this.

Thanks, but it wont work.
This is for selecting file, in my scenario I need to navigate to a folder and select that folder.

Anyways I have created a C# code to achieve this using UiPath.

Please share your code. It could help others, including me :slight_smile:

sure, first add references to Microsoft.Office.Core (Microsoft Office 14.0 Object Library) and Microsoft.Office.Interop.Excel (Microsoft Excel 14.0 Object Library).

Also you need to incorporate the packages as well.

Ans then try the below code afterwards, I have to follow some tricks (using MS excel application) to open the dialog though the code is not opening the excel but the folder selection window.

Microsoft.Office.Interop.Excel.Application app = new Microsoft.Office.Interop.Excel.Application();
Microsoft.Office.Core.FileDialog fileDialog = app.get_FileDialog(Microsoft.Office.Core.MsoFileDialogType.msoFileDialogFolderPicker);
fileDialog.InitialFileName = "c:\\Temp\\"; //something you want
int nres = fileDialog.Show();
if (nres == -1)
{
    Microsoft.Office.Core.FileDialogSelectedItems selectedItems = fileDialog.SelectedItems;

    string[] selectedFolders = selectedItems.Cast<string>().ToArray();

    if (selectedFolders.Length > 0)
    {
        string selectedFolder = selectedFolders[0];
        pdfFolderPath=selectedFolder;

    }
}

Also create an argument and incorporate it in the invoke code.

1 Like

Working code for me vb.net
(Studio 21.10.4, System.Activities 22.10.4, Windows-Legacy project)
Invoke code activity:

Dim xl As New Microsoft.Office.Interop.Excel.ApplicationClass
Dim fd As Microsoft.Office.Core.FileDialog
fd = xl.FileDialog(MsoFileDialogType.msoFileDialogFolderPicker)
fd.Title="Select folder you want to process"
fd.AllowMultiSelect=False
fd.ButtonName="Choose folder"
fd.Show()
result = fd.SelectedItems(0).ToString

fd = Nothing
xl = Nothing

One argument out: result (as String)

I had to import those (as mentioned before):

I was looking for a much better
Open File Dialog than the one that comes with UiPath and I finally came up with this.

The vb/Invoke has 5 arguments

  1. InitialDirectory - In - String
  2. Title - In - String
  3. Filter - In - String
  4. RestoreDirectory - In - Boolean
  5. SelectedFile - Out - String

After the forced update to Windows from Windows/Legacy I have a vb_Invoke
That looks like this.

Code example update found from here:
https://learn.microsoft.com/en-us/dotnet/desktop/wpf/windows/how-to-open-common-system-dialog-box?view=netdesktop-8.0

(the Invoke code starts with next line)
’ *****************************************************
’ Windows/Legacy - Dont Forget to Import the System.Windows.Forms.OpenFileDialog

’ Windows - Dont Forget to Import the Microsoft.Win32
’ *****************************************************

’ For Windows/Legacy
’ Dim OpenFileDialog As New System.Windows.Forms.OpenFileDialog

Dim OpenFileDialog As New Microsoft.Win32.OpenFileDialog

OpenFileDialog.InitialDirectory = InitialDirectory.ToString
OpenFileDialog.Title = Title.ToString
OpenFileDialog.Filter = Filter.ToString
OpenFileDialog.FilterIndex = 1
OpenFileDialog.RestoreDirectory = True

Dim Result As Boolean? = OpenFileDialog.ShowDialog

If Result = True
SelectedFile = OpenFileDialog.FileName
Else
SelectedFile = “”
End If

2 Likes

You don’t need to go through all this hassle. It’s actually quite simple with just simple activities.

Outstanding! Which simple activity allows you to specify a default directory?

Forcing the bot user, when using the File Select Dialog box to perform all of the clicks to move to the desired destination folder locn (when we have it stored as a setting) was not acceptable.

I checked and Default Directory is not a property for the Ui’s FileSelect activity.

Yes the File Select dialog has limitations. Not everyone needs that. You could pass a default value to the text object on the form, and use that with some very simple UI automation to make the dialog automatically go to that folder.

What would be excellent would be to create a custom “browse for file” activity that does incorporate your code and then you could have a default folder property.

In your code, what’s the format expected by OpenFileDialog.Filter?

Ok this is awesome. I took your code, added a few additional properties I think would be useful, and made a custom activity out of it. Here are the files. Thanks for leading me down this path!

Browse For File (Custom).xaml.json (2.5 KB)
Browse For File (Custom).xaml (9.3 KB)

You can just add those to any existing library, or create a new library and copy them in. I used UiPath.System.Activities 23.4.3 but I would imagine any recent version will work.

Hi @Debartha_Mitra_DE

Good trick. But just wondering, how do you make it topmost? At least in Debug, if I have a bunch of opened windows, this dialog will be hidden down below somewhere.

The same thing happens with the official activity. It appears there is no way to control it, including with the vb.net script, because the Win32.OpenFileDialog simply doesn’t have any relevant properties nor methods to do this.

Thank you Paul.

This is the first time I have tried to contribute.

Did you find that the OpenFileDialog.Filter Property value/examples can be found on the Learn.Microsoft.com website?

I appreciate your help.

1 Like

Yes that’s where I found them. There are a ton of them, but some of them didn’t seem useful in an automation context. I also considered adding an option to make it a “select file” or “save file” dialog but I couldn’t see the automation value of a “save file” dialog.

Also, it’s worth noting that their documentation says RestoreFolder is not implemented, so I took that out.