hai,
I am developing an application to copy file or folder from local system to remote system.I am using c# windows application.For the user interface,i need to display the list of files and folders to user during form load itself without using browse button.how can i get this....
Awaiting for suggesstions....
thanks,
saranya
Posted Dec 14, 2007, 12:33 PM
FolderBrowser browser = new FolderBrowser();
browser.ShowDialog();
Or if you are wanting to give the user the ability to select a file, show an OpenFileDialog.
OpenFileDialog openFileDialog = new OpenFileDialog()
openFileDialog.ShowDialog();
Just remember to get and set the current working path because in MS's infinite wisdom ( bless them :P ) they decided that they were going to change the applications working directory to the directory selected in the dialog and not give an option to opt out of it which could cause alot of problems later in the application. Try this:
private string GetFilePath()
{
//Get the current path of the application
string currentPath = Directory.GetCurrentDirectory();
//Create a new dialog
OpenFileDialog openFileDialog = new OpenFileDialog()
try
{
//Show the dialog
if (openFileDialog.ShowDialog() == DialogResult.OK)
return openFileDialog.FileName; //Return path
else
return String.Empty; //Return an empty string
}
finally
{
//Reset directory regardless of dialog result
Directory.SetCurrentDirectory(currentPath);
}
}
That method will show an open file dialog, and if the user clicks OK, it will grab the file path that was specified and return it.