Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Directory Picker 1

Status
Not open for further replies.

jimoo

Programmer
Jun 2, 2003
1,111
US
I posted this in the C# forum, but now believe this a better location. I apologize for the duplicate posting.

I am trying to write some code that will allow me to select a directory. The closest I found is the code below that allows me to select a filename. This code works fine for the filename, but I need just a list of directories and to return the directory name.

Code:
CODEOpenFileDialog fd = new OpenFileDialog();
fd.InitialDirectory = txtDirectory.Text;
fd.ShowDialog();
txtDirectory.Text = fd.FileName;

Jim Osieczonek
Delta Business Group, LLC
 
You will need to use this namespace:
System.IO.DirectoryInfo()

There are methods to get directorys etc. You can then bind the list to a listbox for example for the user to select one or multiple directories.

Hope this helps.

Jim
 
I did see the System.IO.DirectoryInfo(), but did not see how it could be used to return just the directory via a picker of some nature.

Jim Osieczonek
Delta Business Group, LLC
 
OpenFileDialog is related to desktop applications, not web applications. the OpenFileDialog would appear on the server, not the client. causing the system to hang.

instead you would use a FilePicker html control on the client to select the file to upload.

however you want just the directory. there is not a default control for that. this opens you up to security vulnerabilities. if this is an intranet app it may not be an issue. but this is a huge problem for public web applications. In the strictest sense you should treat an intranet app the same way you treat an internet app.

to solve your problem you will need to...
1. have the user upload each file individually
2. build a sliverlight (or dare, I say it, activeX) plug in to allow the user to select a single directory and transfer all the files automatically.
3. create some type of drag/drop plug in (again sliverlight?) where the user could drag a directory from windows explorer onto a control and transfer all the files automatically.

but there is still a fundamental question. why select a directory rather than a single file? and... is the web really the best user interface for this transfer?

depending on the reasons for needing the directory (rather than a file) there may be a better solution. for example: if you were transferring all the files within a specific directory; a windows service which watches the the directory for changes would automatically copy updated files to the server. the server could then process the files if required. all of this would happen automatically when a file is updated/copied to a specific location on the users computer, there would be no GUI for this portion of the system at all.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Did you google, search in help:
Visual Studio Help said:
using System;
using System.IO;

public class GetDirectoriesTest
{
public static void Main()
{

// Make a reference to a directory.
DirectoryInfo di = new DirectoryInfo("c:\\");

// Get a reference to each directory in that directory.
DirectoryInfo[] diArr = di.GetDirectories();

// Display the names of the directories.
foreach (DirectoryInfo dri in diArr)
Console.WriteLine(dri.Name);
}
}
 
I think I need to back up a bit. I have written a ton of Visual Foxpro code and I am now starting to move .NET using C#.

The first app I am writing is a traditional win32 app. I am simply rewriting an app I wrote in VFP.

As jmeckley pointed out - it appears I should have posted this question in another location other an asp.net, but it is here and if you can assist that would be great.

I am simply trying to bring up a picker to allow me to select a directory. In Visual Foxpro it is done like this:

mySelectedDirectory = GETDIRD() and this brings up a dialog box. I can also pass a parameter for a starting directory.

jbenson001 suggestions is great, because I need this logic next to spin through directories for files. However, it is not what I am looking for at this step.

Right now I am simply looking for a dialog box to come up that will allow me to select a directory. I found the code to select a file, but want to select a directory and set the default (startup) directory name.



Jim Osieczonek
Delta Business Group, LLC
 
here are some links on the subject
(c++, so it's not totally straight forward, but not impossible to integrate with .net)
(at a glance it may be promissing.)
(other options.)

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Thank you everyone that has offered some tips. It will take me a few days to get to this and I will let you know what I come up with.

I also looked at the Visual Foxpro Tool Kit for .NET. Someone took the time to write all the VFP functions (especially the nice string functions) in C# so we can add them our projects.

I most likely will not go that route, as I want the app to be all native C# (no libs) but mention it because the author also provides the source code and it is free.

You can download the toolkit and/or source code at:

It is worth checking out.



Jim Osieczonek
Delta Business Group, LLC
 
I most likely will not go that route, as I want the app to be all native C# (no libs)
there is no VFP references in the library you link to. they are simply ideas/classes/functions from VFP ported to the .net framework. if you look at the code there are no references to VFP at all.

don't limit your toolset to only what the .net framework and/or VS provide. there are far more tools and frameworks out there that drastically increase productivity. here are just a few:
R# (resharper)
dotTrace
LLBL Gen Pro
Nhibernate
Castle Project
Rhino Tools
nUnit
Rhino.Mocks
Moq
xUnit
SqlCompare/SqlDataCompare
nant
psake
rake
structure map
ceciel
lucene.net

not to mention codeplex.com and sourceforge.net.

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Thanks you to everyone providing assistance. I found what I was looking for in a few lines of code. The hard part was finding it.

Here is the code. I added it to a click event of a button. For demonstration purposeds I added a messagebox.show()

Code:
FolderBrowserDialog dialog = new FolderBrowserDialog();
dialog.ShowDialog();
string selected = dialog.SelectedPath;

MessageBox.Show(selected);

In case you are interested - here is where I found it:


Jim Osieczonek
Delta Business Group, LLC
 
excellent. just to remove confusion... this applies to desktop apps, not asp.net

Jason Meckley
Programmer
Specialty Bakers, Inc.

faq855-7190
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top