bovender framework
C# framework that implements MVVM and more
ChooseFileSaveAction.cs
1 /* ChooseFileSaveAction.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 using System;
19 using System.Windows.Forms;
20 using System.IO;
21 using System.Text.RegularExpressions;
22 using Bovender;
23 
24 namespace Bovender.Mvvm.Actions
25 {
30  {
31  protected override FileDialog GetDialog(
32  string defaultString,
33  string filter)
34  {
35  Logger.Info("ChooseFileSaveAction.GetDialog");
36  SaveFileDialog dlg = new SaveFileDialog();
37  dlg.Filter = filter;
38  dlg.FileName = PathHelpers.GetFileNamePart(defaultString);
39  dlg.InitialDirectory = PathHelpers.GetDirectoryPart(defaultString);
40  dlg.AddExtension = true;
41  dlg.RestoreDirectory = true;
42  dlg.SupportMultiDottedExtensions = true;
43  dlg.ValidateNames = true;
44  dlg.ShowHelp = false;
45  dlg.OverwritePrompt = true;
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 }
Lets the user choose a file name for saving a file.
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