File and Folder Selection DialogBox


I want to select file and folder (both at a time) using C#.

please help me

LVL 16
Kalpesh ChhatralaSoftware ConsultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Éric MoreauSenior .Net ConsultantCommented:
include a "using System.IO" and use Path from it - quick example:

            OpenFileDialog ofd = new OpenFileDialog();
            DialogResult dr = ofd.ShowDialog();
            string filename = "";
            string directory = "";
            if (dr == DialogResult.OK)
                filename = Path.GetFileName(ofd.FileName);
                directory = Path.GetDirectoryName(ofd.FileName);
Kalpesh ChhatralaSoftware ConsultantAuthor Commented:
i am familiar with OpenFileDialog  class.

I want to select File and Folder from Dialog box. OpenFileDialog box not allowed to select folder.
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

Éric MoreauSenior .Net ConsultantCommented:
I am not sure to understand. The OpenFileDialog let you pick a folder and then a file from that folder no? See the attached image.
Understood.  By default, the selection of files necessitates the navigation of folders.  Therefore, the user would need to indicate, somehow, that they are wanting to select a folder and not navigate down into it to find a file.  I'm guessing you want this functionality so you would not have to use the (non-inheritable) standard dialog classes for selecting files and folders independently.

For this kind of solution, you probably would want to implement a tree view and fill it with folders and files much like "Windows Explorer" would do.  You would then handle the click event, where double-click would navigate into the folder but ctrl+single click would include the folder in the selection, for example. may be what you are looking for?  That walk through sounds like what you are looking for.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Kalpesh ChhatralaSoftware ConsultantAuthor Commented:
thanks d_york.

i understand i need to design this type of dialog box.

do you know this type of dialogbox (file and folder select functionality) available in free ?

thanks for reply.
Éric MoreauSenior .Net ConsultantCommented:
So the file you select is not related to the selected folder. Right?

This is a specific need and you will need to create your own dialog.

I have some code that creates the folders structure in a treeview:
I do not know of any free control that provides that functionality.
Éric MoreauSenior .Net ConsultantCommented:
that suggested comment is not providing a solution for this question!

the solution (building a custom dialog to show folders) is available from https:#40680329
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.