Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted
Updated 10-Aug-11 20:55pm
v2

You have to add this.
objOpenFileDialog.Filter = "Excel files|*.xls;*.xlsx";
 
Share this answer
 
v2
Simple.

C#
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
 
Share this 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[^].
 
Share this answer
 
Comments
CyborgForever 11-Aug-11 2:26am    
I tried the code on my own but it throws some exception so I thought some issues in my code

"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"
This is all you need.

C#
private void button1_Click(...)
{
OpenFileDialog ofd = new OpenFileDialog();
ofd.filter="Excel files|*.xlsx";
ofd.ShowDialog();
}
 
Share this answer
 
v2
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900