C#的OpenFileDialog怎么用
1个回答
展开全部
private void button1_Click(object sender, EventArgs e)
{
OpenFileDialog openFile = new OpenFileDialog();
openFile.Filter = "Excel file|*.xls;*.xlsx|All file|*.*"; //打开文件过滤器
openFile.Title = "打开文件"; //打开对话框标题
if (openFile.ShowDialog() == DialogResult.OK)
{
this.textBox1.Text = openFile.FileName; //选择文件路径给textBox
}
}
如果出现如下错误:
Attempting managed execution inside OS Loader lock. Do not attempt to run managed code inside a DllMain or image initialization function since doing so can cause the application to hang.
请到Debug -> Exceptions-->Find, 输入查找LoaderLock,并将其勾选去掉
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |