客户机上只安装了NET FRAMEWORK2.0
而get_SafeFileName()这个方法需要NET FRAMEWORK2.0 SP1 才能运行
1 dlg.Multiselect = true; 2 dlg.Filter = "txt 文件 (*.txt)|*.txt|Excel 文件 (*.xlsx;*.xls)|*.xls|所有文件 (*.*)|*.*"; 3 if (dlg.ShowDialog() == DialogResult.OK) 4 { 5 6 7 if (filepath != "" && filepath != null) 8 { 9 //SafeFileName net 2.0 找不到SafeFileName方法 10 string FileName = dlg.SafeFileName;
MSDN 查阅资料后,把方法改成
dlg.CheckFileExists = true;
dlg.CheckPathExists = true;
try
{//默认显示桌面
Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
}
catch (Exception)
{
dlg.InitialDirectory = @"C:\";
}
dlg.Multiselect = true;
dlg.Title = "导入通讯录";
dlg.Filter = "Excel 文件 (*.xlsx;*.xls)|*.xls|所有文件 (*.*)|*.*";
if (dlg.ShowDialog() == DialogResult.OK)
{ //关键修改 dlg.SafeFileName;修改成 dlg.FileName;
string FileName = dlg.FileName;
}
经过修改后以上方法解决了