openFileDialog 选择文件
用OpenFileDialog选择文件:
/***选择文件***/#region/***选择文件***/
private void button1_Click(object sender, System.EventArgs e)
{
string folderName =string.Empty;
try
{
openFileDialog.InitialDirectory = @"c:\";
openFileDialog.RestoreDirectory=true;
openFileDialog.Filter = "(*.mdb)|*.*" ;
openFileDialog.FilterIndex=1;
DialogResult fileresult =openFileDialog.ShowDialog();
if (fileresult==DialogResult.OK)
{
string oldFilePath=openFileDialog.FileName;
//System.IO.FileInfo fi = new System.IO.FileInfo(oldFilePath);
//if(fileinfo!=null)
//{
if(oldFilePath.IndexOf(".mdb")>0)
{
this.txtOldfile.Text=oldFilePath;
string strFilePath=System.IO.Path.GetDirectoryName(oldFilePath);
this.p_mdbFullName=oldFilePath;
……
p_savePath=Directory.GetParent(oldFilePath).ToString();
}
else
{
MessageBox.Show(this,"请选择将要操作的Access数据库文件","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
//}
}
else
{
return;
}
}
catch(Exception err)
{
MessageBox.Show(this,err.Message,"选择文件",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
#endregion
private void button1_Click(object sender, System.EventArgs e)
{
string folderName =string.Empty;
try
{
openFileDialog.InitialDirectory = @"c:\";
openFileDialog.RestoreDirectory=true;
openFileDialog.Filter = "(*.mdb)|*.*" ;
openFileDialog.FilterIndex=1;
DialogResult fileresult =openFileDialog.ShowDialog();
if (fileresult==DialogResult.OK)
{
string oldFilePath=openFileDialog.FileName;
//System.IO.FileInfo fi = new System.IO.FileInfo(oldFilePath);
//if(fileinfo!=null)
//{
if(oldFilePath.IndexOf(".mdb")>0)
{
this.txtOldfile.Text=oldFilePath;
string strFilePath=System.IO.Path.GetDirectoryName(oldFilePath);
this.p_mdbFullName=oldFilePath;
……
p_savePath=Directory.GetParent(oldFilePath).ToString();
}
else
{
MessageBox.Show(this,"请选择将要操作的Access数据库文件","提示信息",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
//}
}
else
{
return;
}
}
catch(Exception err)
{
MessageBox.Show(this,err.Message,"选择文件",MessageBoxButtons.OK,MessageBoxIcon.Error);
}
}
#endregion