
2.打开文件
System.Windows.Forms.OpenFileDialog openFileDialog1 = new System.Windows.Forms.OpenFileDialog()
openFileDialog1.InitialDirectory = "c:\\"
openFileDialog1.Filter = "(*.mdb)|*.mdb"
openFileDialog1.FilterIndex = 2
openFileDialog1.RestoreDirectory = true
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//此处做你想做的事
this.txt_datasource.Text = openFileDialog1.FileName
}
3.保存文件
System.Windows.Forms.SaveFileDialog saveDg = new System.Windows.Forms.SaveFileDialog()
saveDg.Filter = "(*.xls)|*.xls|(*.xlsx)|*.xlsx"
saveDg.FileName = tableName+DateTime.Now.ToString("yyyy-MM-dd_hh-mm-ss")+""
saveDg.AddExtension = true
saveDg.RestoreDirectory = true
if (saveDg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
//此处做你想做的事
string filePath = saveDg.FileName
}
4.文件格式过滤
[DefaultValue("")]
[Localizable(true)]
[SRCategoryAttribute("CatBehavior")]
[SRDescriptionAttribute("FDfilterDescr")]
public string Filter { get; set; }