Try File Save Path with SaveFileDialog - CSharp System.Windows.Forms

CSharp examples for System.Windows.Forms:Dialog

Description

Try File Save Path with SaveFileDialog

Demo Code


using System.Windows.Forms;
using System.Windows;
using System.Linq;
using System.Collections.Generic;

public class Main{
        public static bool TryFileSavePath(string dialogTitle, string filter, out string fileName)
        {/*from  w  w  w . j  a  v a2s .  c o m*/
            var fileSelector = new SaveFileDialog()
            {
                Title = dialogTitle,
                Filter = filter,
                DefaultExt = filter.Split('|').ElementAt(1).Replace("*", "") // It SHOULD be an extension method, so todo
            };
            if (fileSelector.ShowDialog() == DialogResult.OK)
            {
                fileName = fileSelector.FileName;
                return true;
            }
            else
            {
                fileName = string.Empty;
                return false;
            }
        }
}

Related Tutorials