Get Path To Save using SaveFileDialog - CSharp System.IO

CSharp examples for System.IO:File Path

Description

Get Path To Save using SaveFileDialog

Demo Code


using System.IO ;
using System.Windows.Forms ;
using System;//from  w w  w  . j  a  va  2s .c om

public class Main{
    public static string GetPathToSave(string title, string defaultName ,string iniDir)
      {
      string extendName = Path.GetExtension(defaultName);            
         SaveFileDialog saveDlg = new SaveFileDialog();
      saveDlg.Filter = string.Format("The Files (*{0})|*{0}", extendName);
      saveDlg.FileName = defaultName;
      saveDlg.InitialDirectory = iniDir;            
         saveDlg.OverwritePrompt = false ;
         if(title != null)
         {
            saveDlg.Title = title ;
         }
         
         DialogResult res = saveDlg.ShowDialog ();
         if(res == DialogResult.OK)
         {
            return saveDlg.FileName ;
         }

         return null ;   
      }
}

Related Tutorials