BrowseForFolderClass.cs
1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
/* ***************************************
* BrowseForFolder.cs
* ---------------------------------------
* - Requirements -
*
* You have to include the
* System.Design.dll in your References
* (Project/Add Reference from menu)
* ---------------------------------------
* - Example -
*
string myPath;
BrowseForFolderClass myFolderBrowser = new BrowseForFolderClass();
myPath = myFolderBrowser.BrowseForFolder("Please, select a folder");
if (myPath.Length > 0)
txtPath.Text = myPath;
* ****************************************/
using System;
using System.Windows.Forms;
using System.Windows.Forms.Design;
namespace ServiceManager
{
public class BrowseForFolderClass : FolderNameEditor
{
FolderNameEditor.FolderBrowser myFolderBrowser;
public string BrowseForFolder(string title)
{
string myPath;
myFolderBrowser = new FolderNameEditor.FolderBrowser();
// Description
myFolderBrowser.Description = title;
// ShowDialog
// myFolderBrowser.DirectoryPath = "c:\\";
myFolderBrowser.ShowDialog();
// DirectoryPath
myPath = myFolderBrowser.DirectoryPath;
// Shall I add the "\" character at the end of the path ?
if (myPath.Length > 0)
{
if (myPath.Substring((myPath.Length - 1), 1) != "\\")
myPath += "\\";
}
// Return correct path
return myPath;
}
~BrowseForFolderClass()
{
myFolderBrowser.Dispose(); // Dispose
}
}
}