bovender framework
C# framework that implements MVVM and more
ChooseFileOpenAction.cs
1 /* ChooseFileOpenAction.cs
2  * part of Daniel's XL Toolbox NG
3  *
4  * Copyright 2014-2018 Daniel Kraus
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */
18 
19 using System;
20 using System.Windows.Forms;
21 using System.IO;
22 using System.Text.RegularExpressions;
23 using Bovender;
24 
25 namespace Bovender.Mvvm.Actions
26 {
31  {
32  protected override FileDialog GetDialog(
33  string defaultString,
34  string filter)
35  {
36  Logger.Info("ChooseFileOpenAction.GetDialog");
37  OpenFileDialog dlg = new OpenFileDialog();
38  dlg.Filter = filter;
39  dlg.FileName = PathHelpers.GetFileNamePart(defaultString);
40  dlg.InitialDirectory = PathHelpers.GetDirectoryPart(defaultString);
41  dlg.AddExtension = true;
42  dlg.RestoreDirectory = true;
43  dlg.SupportMultiDottedExtensions = true;
44  dlg.ValidateNames = true;
45  dlg.ShowHelp = false;
46  return dlg;
47  }
48 
49  #region Class logger
50 
51  private static NLog.Logger Logger { get { return _logger.Value; } }
52 
53  private static readonly Lazy<NLog.Logger> _logger = new Lazy<NLog.Logger>(() => NLog.LogManager.GetCurrentClassLogger());
54 
55  #endregion
56  }
57 }
static string GetDirectoryPart(string path)
Extracts the directory information from path .
Definition: PathHelpers.cs:38
Base class for actions that use dialogs based on System.Windows.Forms.FileDialog. ...
static string GetFileNamePart(string path)
Extracts the file name from path .
Definition: PathHelpers.cs:62
Lets the user choose a file name for opening a file.