added samples
[windows-sources.git] / sdk / samples / FrameworkSamples / CLR / CompressionSample / cs / compression / customfiledialog.cs
blobe8bd011dd6736a05bebc5c25a3077275ebe08c2f
1 //-----------------------------------------------------------------------
2 // This file is part of the Microsoft .NET SDK Code Samples.
3 //
4 // Copyright (C) Microsoft Corporation. All rights reserved.
5 //
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.
9 //
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
13 //PARTICULAR PURPOSE.
14 //-----------------------------------------------------------------------
15 using System;
16 using System.Windows.Forms;
18 namespace Microsoft.Sample.Compression
20 /// <summary>
21 /// File Dialog that has the features for this application.
22 /// </summary>
23 public class CustomFileDialog
25 //Private openFileDialog control
26 private System.Windows.Forms.OpenFileDialog fileDialog;
28 /// <summary>
29 /// Creates a new Custom File Dialog object
30 /// </summary>
31 public CustomFileDialog()
33 fileDialog = new OpenFileDialog();
34 Reset();
37 private void Reset()
39 fileDialog.CheckFileExists = false;
40 fileDialog.CheckPathExists = false;
41 fileDialog.ValidateNames = false;
42 fileDialog.InitialDirectory = ZipConstants.Dot;
44 /// <summary>
45 /// Opens the dialog in add mode
46 /// User can select multiple files
47 /// </summary>
48 /// <returns>
49 /// All the filenames selected
50 ///</returns>
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;
60 return null;
63 /// <summary>
64 /// Opens the dialog in new mode
65 /// User cannot select multiple files
66 /// </summary>
67 /// <returns>
68 /// The filename selected
69 ///</returns>
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;
85 return null;
88 /// <summary>
89 /// Opens the dialog in open mode
90 /// User cannot select multiple files
91 /// </summary>
92 /// <returns>
93 /// The filename selected
94 ///</returns>
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;
109 return null;