1. 程式人生 > >C#儲存檔案、讀取檔案對話方塊

C#儲存檔案、讀取檔案對話方塊

using Microsoft.Win32

//儲存
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            SaveFileDialog dialog = new SaveFileDialog();
            dialog.InitialDirectory = XmlHelp.xmldir;
            dialog.Filter = "配置 (*.xml)|*.xml";
            dialog.DefaultExt = ".xml";
            dialog.Title = "儲存配置檔案";

            if (dialog.ShowDialog() == true)
            {
                string filename0 = dialog.FileName;
                XmlHelp.Saveconfig(itemobjs, filename0);
                common.Appcommon.ConfigPath = filename0;
            }
            
        }

 

//讀取
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.InitialDirectory = XmlHelp.xmldir;
            dialog.Filter = "配置 (*.xml)|*.xml";
            dialog.DefaultExt = ".xml";
            dialog.Title = "選擇配置檔案";

            if (dialog.ShowDialog() == true)
            {
                common.Appcommon.ConfigPath = dialog.FileName;
                List<ItemObj> ites = XmlHelp.Loadconfig(dialog.FileName);
                
            }
        }