1 //-----------------------------------------------------------------------
2 // This file is part of the Microsoft .NET SDK Code Samples.
4 // Copyright (C) Microsoft Corporation. All rights reserved.
6 //This source code is intended only as a supplement to Microsoft
7 //Development Tools and/or on-line documentation. See these other
8 //materials for detailed information regarding Microsoft code samples.
10 //THIS CODE AND INFORMATION ARE PROVIDED AS IS WITHOUT WARRANTY OF ANY
11 //KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
12 //IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
14 //-----------------------------------------------------------------------
16 using System
.Windows
.Forms
;
18 namespace Microsoft
.Sample
.Compression
21 /// File Dialog that has the features for this application.
23 public class CustomFileDialog
25 //Private openFileDialog control
26 private System
.Windows
.Forms
.OpenFileDialog fileDialog
;
29 /// Creates a new Custom File Dialog object
31 public CustomFileDialog()
33 fileDialog
= new OpenFileDialog();
39 fileDialog
.CheckFileExists
= false;
40 fileDialog
.CheckPathExists
= false;
41 fileDialog
.ValidateNames
= false;
42 fileDialog
.InitialDirectory
= ZipConstants
.Dot
;
45 /// Opens the dialog in add mode
46 /// User can select multiple files
49 /// All the filenames selected
51 public string[] AddMode()
53 fileDialog
.FileName
= String
.Empty
;
54 fileDialog
.Multiselect
= true;
55 fileDialog
.Title
= ZipConstants
.AddFiles
;
56 fileDialog
.Filter
= ZipConstants
.AllExtensions
;
57 DialogResult dr
= fileDialog
.ShowDialog();
58 if (dr
== DialogResult
.OK
)
59 return fileDialog
.FileNames
;
64 /// Opens the dialog in new mode
65 /// User cannot select multiple files
68 /// The filename selected
70 public string NewMode()
72 fileDialog
.FileName
= String
.Empty
;
73 fileDialog
.Multiselect
= false;
74 fileDialog
.Title
= ZipConstants
.NewArchive
;
75 fileDialog
.Filter
= ZipConstants
.Extension
;
76 //In case the filedialog does not add extensions
78 DialogResult dr
= fileDialog
.ShowDialog();
79 if (dr
== DialogResult
.OK
)
81 if (!fileDialog
.FileName
.Contains(".xip"))
82 fileDialog
.FileName
+= ".xip";
83 return fileDialog
.FileName
;
89 /// Opens the dialog in open mode
90 /// User cannot select multiple files
93 /// The filename selected
95 public string OpenMode()
97 fileDialog
.FileName
= String
.Empty
;
99 fileDialog
.Multiselect
= false;
100 fileDialog
.Title
= ZipConstants
.OpenArchive
;
101 fileDialog
.Filter
= ZipConstants
.Extension
;
102 DialogResult dr
= fileDialog
.ShowDialog();
103 if (dr
== DialogResult
.OK
)
105 if (!fileDialog
.FileName
.Contains(ZipConstants
.Dot
))
106 fileDialog
.FileName
+= ".xip";
107 return fileDialog
.FileName
;