Line | |
---|
1 | using System.IO;
|
---|
2 | using System.Windows.Forms;
|
---|
3 |
|
---|
4 | namespace Common
|
---|
5 | {
|
---|
6 | class Dialogs
|
---|
7 | {
|
---|
8 | public const string AnyFile = "Any file";
|
---|
9 |
|
---|
10 | public static string OpenFileDialog(string fileName, string fileType, string fileExtension)
|
---|
11 | {
|
---|
12 | OpenFileDialog dlg = new OpenFileDialog { Filter = fileType + @"|*." + fileExtension + @"|" + AnyFile + @"|*.*", DefaultExt = fileExtension };
|
---|
13 | if (!string.IsNullOrEmpty(fileName))
|
---|
14 | {
|
---|
15 | dlg.FileName = Path.GetFileName(fileName);
|
---|
16 | dlg.InitialDirectory = Path.GetDirectoryName(fileName);
|
---|
17 | }
|
---|
18 |
|
---|
19 | if (dlg.ShowDialog() == DialogResult.OK)
|
---|
20 | {
|
---|
21 | fileName = dlg.FileName;
|
---|
22 | }
|
---|
23 | return fileName;
|
---|
24 | }
|
---|
25 |
|
---|
26 | public static string SaveFileDialog(string fileName, string fileType, string fileExtension)
|
---|
27 | {
|
---|
28 | SaveFileDialog dlg = new SaveFileDialog { Filter = fileType + @"|*." + fileExtension + @"|" + AnyFile + @"|*.*", DefaultExt = fileExtension };
|
---|
29 | if (!string.IsNullOrEmpty(fileName))
|
---|
30 | {
|
---|
31 | dlg.FileName = Path.GetFileName(fileName);
|
---|
32 | dlg.InitialDirectory = Path.GetDirectoryName(fileName);
|
---|
33 | }
|
---|
34 |
|
---|
35 | if (dlg.ShowDialog() == DialogResult.OK)
|
---|
36 | {
|
---|
37 | fileName = dlg.FileName;
|
---|
38 | }
|
---|
39 | return fileName;
|
---|
40 | }
|
---|
41 | }
|
---|
42 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.