求助:关于获取路径问题
是这样的,在form窗体上有两个按钮,一个为btnImpor "导入Excel",另一个为btnExpor "导出Excel"要求点击btnImpor时,会弹出openfiledialog对话框,获取用户选择的文件路径
点击btnExpor时,会弹出savefiledialog对话框,获取用户选择的路径和文件名
我的代码btnImpor调用方法时报错,btnExpor不写方法调用也报错,求解。
public string OpenFileDialogGetPath()
{
string path = "";
using (OpenFileDialog ofd = new OpenFileDialog())
{
ofd.InitialDirectory = "c:\\";
ofd.Filter = "Excel文档(*.xls)|*.xls";
if (ofd.ShowDialog() == DialogResult.OK)
{
path = ofd.FileName;
}
}
return path;
}
string path = "";
SaveFileDialog sf = new SaveFileDialog();
sf.InitialDirectory = "d:\\";
sf.Filter = "Excel文档|*.xls";
if (sf.ShowDialog() == DialogResult.OK)
{
path = sf.FileName;
}
MessageBox.Show(path);