Save File with SaveFileDialog - CSharp System.Windows.Forms

CSharp examples for System.Windows.Forms:Dialog

Description

Save File with SaveFileDialog

Demo Code


using System.Windows.Forms;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System;/*from  w ww  . j a v a2  s .c o  m*/

public class Main{
        public static string SaveFile(string defaultExt = "")
        {
            string filPath = string.Empty;
            SaveFileDialog dialog = new SaveFileDialog();
            if (!string.IsNullOrWhiteSpace(defaultExt))
            {
                dialog.DefaultExt = defaultExt;
                dialog.AddExtension = true;
            }
            dialog.Filter = "????(*.*)|*.*";
            dialog.FilterIndex = 0;
            dialog.DereferenceLinks = true;
            dialog.RestoreDirectory = false;

            if (dialog.ShowDialog() == DialogResult.OK)
            {
                filPath = dialog.FileName;
            }
            return filPath;
        }
}

Related Tutorials