基于单击按钮的“打开文件"对话框 [英] Open File dialog based on button click

查看:57
本文介绍了基于单击按钮的“打开文件"对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

感谢所有共享代码的人.但是当我使用openfiledialog
时,我将面临foll异常

必须先将当前线程设置为单线程单元(STA)模式,然后才能进行OLE调用.
确保您的Main函数上已标记STAThreadAttribute.仅当
调试器已附加到该进程中."

在此先感谢

Thanks to all who shared code. but I''m facing the foll exception when I use openfiledialog


"Current thread must be set to single thread apartment (STA) mode before OLE calls can be made.
Ensure that your Main function has STAThreadAttribute marked on it. This exception is only raised if a
debugger is attached to the process"

Thanks in advance

推荐答案

您必须添加它.
You have to add this.
objOpenFileDialog.Filter = "Excel files|*.xls;*.xlsx";


简单.

Simple.

OpenFileDialog fileD = new OpenFileDialog(); //create object
fileD.Filter = "Excel files|*.xls;*.xlsx"; //define filter
fileD.ShowDialog(); //show dialog
MessageBox.show(fileD.fileName); //Get uploaded file


所有您在CP上提出的问题属于基本水平.
我认为没有人会为这种简单的任务提供代码.
并且,请在发布到CP之前先查询您的查询,如果找不到其他合适的解决方案,可以在CP上询问.

这是您 answer [
All of your question asked on CP are of basic level.
I think nobody will provide code for this type of simple task.
And please Google your query before posting on CP and if you are unable to find any suitable solution than ask on CP.

Here is you answer[^].


这篇关于基于单击按钮的“打开文件"对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆